Skip to content

Commit

Permalink
Merge pull request #1123 from DDMAL/toggle-syllable-fix
Browse files Browse the repository at this point in the history
Check if contain linked syllable for group action
  • Loading branch information
yinanazhou authored Oct 30, 2023
2 parents 73393cf + fd5b4f1 commit 6f00c22
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/SquareEdit/Grouping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function initNeonView (view: NeonView): void {

/**
* Check if selected elements can be grouped or not
* @returns true if grouped, false otherwise
* @returns true if can be grouped, false otherwise
*/
export function isGroupable(selectionType: string, elements: Array<SVGGraphicsElement>): boolean {
const groups = Array.from(elements.values()) as SVGGraphicsElement[];
Expand All @@ -51,6 +51,40 @@ export function isGroupable(selectionType: string, elements: Array<SVGGraphicsEl
}


function containsLinked (selectionType:string, elements?: Array<SVGGraphicsElement>) {
if (!elements) {
elements = Array.from(document.querySelectorAll('.selected')) as SVGGraphicsElement[];
}
switch (selectionType) {
case 'selBySyllable':
for (const element of elements) {
if (element.hasAttribute('mei:follows') || element.hasAttribute('mei:precedes')) {
Notification.queueNotification('The action involves linked syllables, please untoggle them first', 'warning');
return true;
}
}
return false;

case 'selByNeume':
for (const element of elements) {
if (element.parentElement.hasAttribute('mei:follows') || element.parentElement.hasAttribute('mei:precedes')) {
Notification.queueNotification('The action involves linked syllables, please untoggle them first', 'warning');
return true;
}
}
return false;

case 'selByNc':
for (const element of elements) {
if (element.parentElement.parentElement.hasAttribute('mei:follows') || element.parentElement.parentElement.hasAttribute('mei:precedes')) {
Notification.queueNotification('The action involves linked syllables, please untoggle them first', 'warning');
return true;
}
}
return false;
}
}

/**
* Checks to see is a selection of elements is already linked
* @param elements elements to be considered
Expand Down Expand Up @@ -196,6 +230,7 @@ export function initGroupingListeners (): void {

try {
document.getElementById('mergeSyls').addEventListener('click', () => {
if (containsLinked(SelectTools.getSelectionType())) return;
const elementIds = getChildrenIds().filter(e =>
document.getElementById(e).classList.contains('neume')
);
Expand All @@ -205,6 +240,7 @@ export function initGroupingListeners (): void {

try {
document.getElementById('groupNeumes').addEventListener('click', () => {
if (containsLinked(SelectTools.getSelectionType())) return;
const elementIds = getIds();
groupingAction('group', 'neume', elementIds);
});
Expand Down Expand Up @@ -272,6 +308,8 @@ const keydownListener = function(e) {

const selectionType = SelectTools.getSelectionType();

if (containsLinked(selectionType, elements)) return;

// Group/merge or ungroup/split based on selection type
switch (selectionType) {
case 'selBySyllable':
Expand Down

0 comments on commit 6f00c22

Please sign in to comment.