-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,6 +236,23 @@ export const SelectionHandler = ( | |
}); | ||
} | ||
|
||
const onKeyup = (evt: KeyboardEvent) => { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rsimon
Author
Member
|
||
if (evt.key === 'Shift' && currentTarget) { | ||
// Proper lifecycle management: clear selection first... | ||
selection.clear(); | ||
|
||
// ...then add annotation to store... | ||
store.addAnnotation({ | ||
id: currentTarget.annotation, | ||
bodies: [], | ||
target: currentTarget | ||
}); | ||
|
||
// ...then make the new annotation the current selection | ||
selection.userSelect(currentTarget.annotation, cloneKeyboardEvent(evt)); | ||
} | ||
} | ||
|
||
hotkeys(SELECTION_KEYS.join(','), { element: container, keydown: true, keyup: false }, (evt) => { | ||
if (!evt.repeat) | ||
lastDownEvent = cloneKeyboardEvent(evt); | ||
|
@@ -267,6 +284,7 @@ export const SelectionHandler = ( | |
document.addEventListener('pointerup', onPointerUp); | ||
|
||
if (annotatingEnabled) { | ||
container.addEventListener('keyup', onKeyup); | ||
container.addEventListener('selectstart', onSelectStart); | ||
document.addEventListener('selectionchange', onSelectionChange); | ||
} | ||
|
@@ -275,6 +293,7 @@ export const SelectionHandler = ( | |
container.removeEventListener('pointerdown', onPointerDown); | ||
document.removeEventListener('pointerup', onPointerUp); | ||
|
||
container.removeEventListener('keyup', onKeyup); | ||
container.removeEventListener('selectstart', onSelectStart); | ||
document.removeEventListener('selectionchange', onSelectionChange); | ||
|
||
|
Warning from stepping on the same rake as me ⚠
In the #118 I intentionally didn't go with creation annotation upon lifting the key. It makes it complicated and error-prone to decide:
Ctrl + A
lifting eventCreating the annotation immediately and then gradually updating it on the
selectionchange
turned out to be more convenient to maintain.