Skip to content

Commit

Permalink
Merge pull request #1202 from DDMAL/add-syl
Browse files Browse the repository at this point in the history
Fix precedes/follows sandwich highlight & syl
  • Loading branch information
yinanazhou authored Mar 11, 2024
2 parents 83bdb58 + 92a9b97 commit d8ccf7b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
22 changes: 22 additions & 0 deletions src/utils/EditControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ export function initNavbar (neonView: NeonView): void {
attrValue: ''
}
});

param.push(...addSylAction([syllable, precedesSyllable, followsSyllable]));
}
else if (syllable.hasAttribute('precedes')) {
const precedesSyllable = syllables.find(element => element.getAttribute('xml:id') === syllable.getAttribute('precedes').substring(1));
Expand Down Expand Up @@ -373,6 +375,7 @@ export function initNavbar (neonView: NeonView): void {
}
});
}
param.push(...addSylAction([syllable, precedesSyllable]));
}
else if (syllable.hasAttribute('follows')) {
const followsSyllable = syllables.find(element => element.getAttribute('xml:id') === syllable.getAttribute('follows').substring(1));
Expand Down Expand Up @@ -406,6 +409,7 @@ export function initNavbar (neonView: NeonView): void {
}
});
}
param.push(...addSylAction([syllable, followsSyllable]));
}
}

Expand Down Expand Up @@ -517,3 +521,21 @@ export function initUndoRedoPanel (neonView: NeonView): void {
}
});
}

function addSylAction(syllables: Element[]): Array<EditorAction> {
const param = new Array<EditorAction>();

for (const syllable of syllables) {
if (!syllable.getElementsByTagName('syl').length) {
param.push({
action: 'setText',
param: {
elementId: syllable.getAttribute('xml:id'),
text: '',
}
});
}
}

return param;
}
31 changes: 22 additions & 9 deletions src/utils/SelectTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,28 @@ export async function selectAll (elements: Array<SVGGraphicsElement>, neonView:
groupsToSelect.add(grouping);

// Check for precedes/follows
const follows = grouping.getAttribute('mei:follows');
if (follows) {
document.querySelector('#' + follows.slice(1)).classList.add('no-moving');
groupsToSelect.add(document.querySelector('#' + follows.slice(1)));
}
const precedes = grouping.getAttribute('mei:precedes');
if (precedes) {
document.querySelector('#' + precedes.slice(1)).classList.add('no-moving');
groupsToSelect.add(document.querySelector('#' + precedes.slice(1)));
let selected = grouping;
let follows = selected.getAttribute('mei:follows');
let precedes = selected.getAttribute('mei:precedes');
while (follows || precedes){
if (follows) {
selected = document.querySelector('#' + follows.slice(1));
if (groupsToSelect.has(selected)) {
break;
}
selected.classList.add('no-moving');
groupsToSelect.add(selected);
follows = selected.getAttribute('mei:follows');
}
if (precedes) {
selected = document.querySelector('#' + precedes.slice(1));
if (groupsToSelect.has(selected)) {
break;
}
selected.classList.add('no-moving');
groupsToSelect.add(selected);
precedes = selected.getAttribute('mei:precedes');
}
}
}
// Select the elements
Expand Down

0 comments on commit d8ccf7b

Please sign in to comment.