Skip to content

Commit

Permalink
Allowed shifting over the selection content
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-danylchenko committed Jul 18, 2024
1 parent 1780bf0 commit 11aae73
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/text-annotator/src/SelectionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,6 @@ export const SelectionHandler = (
}
container.addEventListener('pointerdown', onPointerDown);

const onKeyDown = (evt: KeyboardEvent) => {
if (!evt.repeat) {
lastDownEvent = cloneKeyboardEvent(evt);
}
}
container.addEventListener('keydown', onKeyDown);

const onPointerUp = (evt: PointerEvent) => {
const annotatable = !(evt.target as Node).parentElement?.closest(NOT_ANNOTATABLE_SELECTOR);
if (!annotatable || !isLeftClick)
Expand Down Expand Up @@ -173,9 +166,19 @@ export const SelectionHandler = (
}
document.addEventListener('pointerup', onPointerUp);

/**
* Track arbitrary keydown events to use them during
* the `selectionchange` annotation selection.
*/
hotkeys('*', { element: container, keyup: false, keydown: true }, (evt, handler) => {
if (!evt.repeat) {
lastDownEvent = cloneKeyboardEvent(evt);
}
});

/**
* Track the "Shift" key lift which signifies the end of a select operation.
* Unfortunately, we cannot track modifier key immediately, so a wildcard is used
* Unfortunately, we cannot track modifier key immediately, so the wildcard is used.
*/
hotkeys('*', { keyup: true, keydown: false }, (evt) => {
if (hotkeys.shift && evt.key === Key.Shift) {
Expand Down Expand Up @@ -210,7 +213,6 @@ export const SelectionHandler = (
container.removeEventListener('pointerdown', onPointerDown);
document.removeEventListener('pointerup', onPointerUp);

container.removeEventListener('keydown', onKeyDown);
hotkeys.unbind();
}

Expand Down

0 comments on commit 11aae73

Please sign in to comment.