Skip to content

Check if contain linked syllable for group action #1123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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