Skip to content

Commit

Permalink
Device-specific 'select all' key
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimon committed Oct 2, 2024
1 parent 85e351a commit c8000a1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/text-annotator/src/SelectionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
debounce,
splitAnnotatableRanges,
rangeToSelector,
isMac,
isWhitespaceOrEmpty,
trimRangeToContainer,
NOT_ANNOTATABLE_SELECTOR
Expand All @@ -19,11 +20,11 @@ const CLICK_TIMEOUT = 300;

const ARROW_KEYS = ['up', 'down', 'left', 'right'];

const SELECT_ALL = ['ctrl+a', '⌘+a'];
const SELECT_ALL = isMac ? '⌘+a' : 'ctrl+a';

const SELECTION_KEYS = [
...ARROW_KEYS.map(key => `shift+${key}`),
...SELECT_ALL
SELECT_ALL
];

export const SelectionHandler = (
Expand Down Expand Up @@ -271,7 +272,7 @@ export const SelectionHandler = (
lastDownEvent = cloneKeyboardEvent(evt);
});

hotkeys(SELECT_ALL.join(','), { keydown: true, keyup: false}, evt => {
hotkeys(SELECT_ALL, { keydown: true, keyup: false}, evt => {
lastDownEvent = cloneKeyboardEvent(evt);
onSelectAll(evt);
});
Expand Down
2 changes: 2 additions & 0 deletions packages/text-annotator/src/utils/device.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-ignore
export const isMac = /mac/i.test(navigator.userAgentData ? navigator.userAgentData.platform : navigator.platform);
1 change: 1 addition & 0 deletions packages/text-annotator/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './cancelSingleClickEvents';
export * from './device';
export * from './programmaticallyFocusable';
export * from './debounce';
export * from './getAnnotatableFragment';
Expand Down

0 comments on commit c8000a1

Please sign in to comment.