Skip to content

Commit

Permalink
Merge pull request #1463 from silx-kit/cancel-zoom-right-click
Browse files Browse the repository at this point in the history
Allow canceling select-to-zoom interaction with right click
  • Loading branch information
axelboc authored Aug 8, 2023
2 parents f609c92 + 9357917 commit d912a67
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/lib/src/interactions/SelectionTool.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { assertDefined } from '@h5web/shared';
import {
useEventListener,
useKeyboardEvent,
usePrevious,
useRafState,
Expand Down Expand Up @@ -138,15 +139,16 @@ function SelectionTool(props: Props) {

useCanvasEvents({ onPointerDown, onPointerMove, onPointerUp });

useKeyboardEvent(
'Escape',
() => {
startEvtRef.current = undefined;
setRawSelection(undefined);
},
[],
{ event: 'keydown' },
);
function cancelSelection() {
startEvtRef.current = undefined;
setRawSelection(undefined);
}

useKeyboardEvent('Escape', cancelSelection, [], { event: 'keydown' });
useEventListener(window, 'contextmenu', (evt: MouseEvent) => {
evt.preventDefault();
cancelSelection();
});

// Compute effective selection
const selection = useMemo(
Expand Down

0 comments on commit d912a67

Please sign in to comment.