Skip to content
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

Fix selections growing to include annotations after selection end #4864

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,13 @@
const selectionType = annotationState.isQuestionMode ? "question" : "annotation";
document.querySelector(".code-table")?.classList.add(`selection-color-${selectionType}`);
document.body.classList.add("no-selection-outside-code");
document.body.classList.add("no-selection-inside-annotations");
}

function removeSelectionClasses(): void {
document.querySelector(".code-table")?.classList.remove("selection-color-annotation", "selection-color-question");
document.body.classList.remove("no-selection-outside-code");
document.body.classList.remove("no-selection-inside-annotations");
}

export async function triggerSelectionEnd(): Promise<void> {
Expand All @@ -188,9 +190,17 @@
if (!selection.isCollapsed && !anyRangeInAnnotation(selection)) {
userAnnotationState.selectedRange = selectedRangeFromSelection(selection);
if (userAnnotationState.selectedRange) {
const selectionType = annotationState.isQuestionMode ? "question" : "annotation";
document.querySelector(".code-table")?.classList.add(`selection-color-${selectionType}`);
// we might not have started with the selection inside the code
// But we ended with a code selection, so add the selection classes
addSelectionClasses();

Check warning on line 195 in app/assets/javascripts/components/annotations/selectionHelpers.ts

View check run for this annotation

Codecov / codecov/patch

app/assets/javascripts/components/annotations/selectionHelpers.ts#L195

Added line #L195 was not covered by tests
// starting a new selection outside the code should be allowed
document.body.classList.remove("no-selection-outside-code");

// Next time the selection is changed, remove the selection classes
const unsubscribe = userAnnotationState.subscribe( () => {
removeSelectionClasses();
unsubscribe();

Check warning on line 202 in app/assets/javascripts/components/annotations/selectionHelpers.ts

View check run for this annotation

Codecov / codecov/patch

app/assets/javascripts/components/annotations/selectionHelpers.ts#L200-L202

Added lines #L200 - L202 were not covered by tests
}, "selectedRange");
} else {
removeSelectionClasses();
}
Expand Down
6 changes: 6 additions & 0 deletions app/assets/stylesheets/components/code_listing.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,9 @@ d-selection-marker {
}
}
}

.no-selection-inside-annotations {
d-code-listing-row td d-annotations-cell {
user-select: none;
}
}
Loading