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 Shift+Click selection #287

Merged
merged 2 commits into from
Jun 8, 2021
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
18 changes: 18 additions & 0 deletions media/editor/selectHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ export class SelectHandler {
this.renderSelection(toRender);
}

/***
* @description Returns the offset of the anchor cell that is used for
* expanding the selection using Shift+Click.
* @returns {number} The offset of the anchor cell
*/
public getAnchor(): number | undefined {
return WebviewStateManager.getProperty("selection_anchor");
}

/***
* @description Set the offset of the anchor cell that is used for expanding
* the selection using Shift+Click.
* @param {number} offset The offset of the anchor cell
*/
public setAnchor(offset: number): void {
WebviewStateManager.setProperty("selection_anchor", offset);
}

/***
* @description Renders the updated selection state of selected/unselected elements
* @param {number[]} offsets The offsets of the elements to render
Expand Down
10 changes: 7 additions & 3 deletions media/editor/virtualDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,19 @@ export class VirtualDocument {
const offset = getElementsOffset(target);
if (event.shiftKey) {
const startSelection = this.selectHandler.getSelectionStart();
const currentSelection = this.selectHandler.getSelected();
if (startSelection !== undefined) {
this.selectHandler.setFocused(offset);
const min = Math.min(startSelection, offset);
const max = Math.max(offset, currentSelection[currentSelection.length - 1]);
let selectionAnchor = this.selectHandler.getAnchor();
if (selectionAnchor === undefined) {
selectionAnchor = offset;
}
const min = Math.min(selectionAnchor, offset);
const max = Math.max(offset, selectionAnchor);
this.selectHandler.setSelected(createOffsetRange(min, max));
target.focus({ preventScroll: true });
}
} else {
this.selectHandler.setAnchor(offset);
this.selectHandler.setFocused(offset);
if (event.ctrlKey) {
const selection = this.selectHandler.getSelected();
Expand Down