diff options
Diffstat (limited to 'src/client/views/GlobalKeyHandler.ts')
-rw-r--r-- | src/client/views/GlobalKeyHandler.ts | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/client/views/GlobalKeyHandler.ts b/src/client/views/GlobalKeyHandler.ts index 0c05a1b69..fb360ee26 100644 --- a/src/client/views/GlobalKeyHandler.ts +++ b/src/client/views/GlobalKeyHandler.ts @@ -1,4 +1,4 @@ -import { action } from "mobx"; +import { action, observable } from "mobx"; import { DateField } from "../../fields/DateField"; import { Doc, DocListCast } from "../../fields/Doc"; import { Id } from "../../fields/FieldSymbols"; @@ -37,6 +37,7 @@ type KeyControlInfo = { export class KeyManager { public static Instance: KeyManager = new KeyManager(); private router = new Map<string, KeyHandler>(); + @observable ShiftPressed = false; constructor() { const isMac = navigator.platform.toLowerCase().indexOf("mac") >= 0; @@ -49,7 +50,13 @@ export class KeyManager { this.router.set("1000", this.shift); } - public handle = async (e: KeyboardEvent) => { + public unhandle = action((e: KeyboardEvent) => { + if (e.key?.toLowerCase() === "shift") KeyManager.Instance.ShiftPressed = false; + }); + + public handle = action(async (e: KeyboardEvent) => { + if (e.key?.toLowerCase() === "shift" && e.ctrlKey && e.altKey) KeyManager.Instance.ShiftPressed = true; + if (!Doc.UserDoc().noviceMode && e.key.toLocaleLowerCase() === "shift") DocServer.UPDATE_SERVER_CACHE(true); const keyname = e.key && e.key.toLowerCase(); this.handleGreedy(keyname); @@ -69,7 +76,7 @@ export class KeyManager { control.stopPropagation && e.stopPropagation(); control.preventDefault && e.preventDefault(); - } + }); private handleGreedy = action((keyname: string) => { switch (keyname) { @@ -128,7 +135,7 @@ export class KeyManager { }; }); - private shift = async (keyname: string) => { + private shift = action(async (keyname: string) => { const stopPropagation = false; const preventDefault = false; @@ -143,7 +150,7 @@ export class KeyManager { stopPropagation: stopPropagation, preventDefault: preventDefault }; - } + }); private alt = action((keyname: string) => { const stopPropagation = true; @@ -216,6 +223,11 @@ export class KeyManager { stopPropagation = false; break; case "a": + if (e.target !== document.body) { + stopPropagation = false; + preventDefault = false; + } + break; case "v": stopPropagation = false; preventDefault = false; |