Skip to content

Commit

Permalink
fix: allow arrow keys to work when focused element is outside viewport
Browse files Browse the repository at this point in the history
Fixes #219
  • Loading branch information
connor4312 committed Dec 10, 2022
1 parent 00087f9 commit 2ee2fc1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions media/editor/dataDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,15 @@ export const DataDisplay: React.FC = () => {
ctx.unsavedRanges = unsavedRanges;
}, [editTimeline, unsavedEditIndex]);

const onKeyDown = (e: React.KeyboardEvent) => {

useGlobalHandler("keydown", (e: KeyboardEvent) => {
// handle keydown events not sent to a more specific element. The user can
// scroll to a point where the 'focused' element is no longer rendered,
// but we still want to allow use of arrow keys.
if (document.activeElement !== document.body && !containerRef.current?.contains(document.activeElement)) {
return;
}

const current = ctx.focusedElement || FocusedElement.zero;
const displayedBytes = select.getDisplayedBytes(dimensions, columnWidth);

Expand Down Expand Up @@ -272,7 +280,7 @@ export const DataDisplay: React.FC = () => {
} else {
ctx.setSelectionRanges([Range.single(next.byte)]);
}
};
}, [dimensions, columnWidth, fileSize]);

useGlobalHandler<ClipboardEvent>("paste", evt => {
const target = document.activeElement;
Expand All @@ -298,11 +306,7 @@ export const DataDisplay: React.FC = () => {

const clearPasting = useCallback(() => setPasting(undefined), []);

return <div
ref={containerRef}
className={dataDisplayCls}
onKeyDown={onKeyDown}
>
return <div ref={containerRef} className={dataDisplayCls}>
<DataRows />
<PastePopup context={pasting} hide={clearPasting} />
</div>;
Expand Down

0 comments on commit 2ee2fc1

Please sign in to comment.