PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
tableberg / src / utils / modifier-keys.ts

modifier-keys.ts in Tableberg – Simple Gutenberg Table Block 1.1.5, at src/utils/modifier-keys.ts

36 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Tracks whether a selection modifier key (Ctrl / Cmd / Shift) is currently
3 * held down. While a modifier is held, cell-selection handlers preserve the
4 * existing selection so a multi-cell selection can be built up for merging.
5 *
6 * State is synced from keydown/keyup as well as mousedown — the mousedown sync
7 * (capture phase) runs before the selection handlers, guaranteeing an accurate
8 * value at the moment those handlers check it, even if a keydown landed
9 * in a document we aren't listening to.
10 *
11 * Listeners are attached per-document so this works in both the iframed and
12 * non-iframed editor.
13 */
14
15 let modifierActive = false;
16
17 function sync(event: KeyboardEvent | MouseEvent): void {
18 modifierActive = event.ctrlKey || event.metaKey || event.shiftKey;
19 }
20
21 export function isModifierActive(): boolean {
22 return modifierActive;
23 }
24
25 export function trackModifierKeys(doc: Document): () => void {
26 doc.addEventListener("keydown", sync, true);
27 doc.addEventListener("keyup", sync, true);
28 doc.addEventListener("mousedown", sync, true);
29
30 return () => {
31 doc.removeEventListener("keydown", sync, true);
32 doc.removeEventListener("keyup", sync, true);
33 doc.removeEventListener("mousedown", sync, true);
34 };
35 }
36