diff options
Diffstat (limited to 'src/client/views/GlobalKeyHandler.ts')
-rw-r--r-- | src/client/views/GlobalKeyHandler.ts | 132 |
1 files changed, 39 insertions, 93 deletions
diff --git a/src/client/views/GlobalKeyHandler.ts b/src/client/views/GlobalKeyHandler.ts index be6aa6be2..83c02b09b 100644 --- a/src/client/views/GlobalKeyHandler.ts +++ b/src/client/views/GlobalKeyHandler.ts @@ -6,23 +6,26 @@ import { InkTool } from "../../fields/InkField"; import { List } from "../../fields/List"; import { ScriptField } from "../../fields/ScriptField"; import { Cast, PromiseValue } from "../../fields/Types"; -import GoogleAuthenticationManager from "../apis/GoogleAuthenticationManager"; +import { GoogleAuthenticationManager } from "../apis/GoogleAuthenticationManager"; import { DocServer } from "../DocServer"; import { DocumentType } from "../documents/DocumentTypes"; import { DictationManager } from "../util/DictationManager"; import { DragManager } from "../util/DragManager"; +import { GroupManager } from "../util/GroupManager"; import { SelectionManager } from "../util/SelectionManager"; -import SharingManager from "../util/SharingManager"; +import { SharingManager } from "../util/SharingManager"; import { undoBatch, UndoManager } from "../util/UndoManager"; import { CollectionDockingView } from "./collections/CollectionDockingView"; +import { CollectionFreeFormViewChrome } from "./collections/CollectionMenu"; +import { ContextMenu } from "./ContextMenu"; import { DocumentDecorations } from "./DocumentDecorations"; +import { InkStrokeProperties } from "./InkStrokeProperties"; import { MainView } from "./MainView"; -import { DocumentView } from "./nodes/DocumentView"; import { DocumentLinksButton } from "./nodes/DocumentLinksButton"; -import PDFMenu from "./pdf/PDFMenu"; -import { ContextMenu } from "./ContextMenu"; -import GroupManager from "../util/GroupManager"; -import { CollectionFreeFormViewChrome } from "./collections/CollectionMenu"; +import { DocumentView } from "./nodes/DocumentView"; +import { PDFMenu } from "./pdf/PDFMenu"; +import { SnappingManager } from "../util/SnappingManager"; +import { SearchBox } from "./search/SearchBox"; const modifiers = ["control", "meta", "shift", "alt"]; type KeyHandler = (keycode: string, e: KeyboardEvent) => KeyControlInfo | Promise<KeyControlInfo>; @@ -31,7 +34,7 @@ type KeyControlInfo = { stopPropagation: boolean }; -export default class KeyManager { +export class KeyManager { public static Instance: KeyManager = new KeyManager(); private router = new Map<string, KeyHandler>(); @@ -81,26 +84,18 @@ export default class KeyManager { // MarqueeView.DragMarquee = !MarqueeView.DragMarquee; // bcz: this needs a better disclosure UI break; case "escape": - // if (DocumentLinksButton.StartLink) { - // if (DocumentLinksButton.StartLink.Document) { - // action((e: React.PointerEvent<HTMLDivElement>) => { - // Doc.UnBrushDoc(DocumentLinksButton.StartLink?.Document as Doc); - // }); - // } - // } DocumentLinksButton.StartLink = undefined; + DocumentLinksButton.StartLinkView = undefined; + InkStrokeProperties.Instance && (InkStrokeProperties.Instance._controlBtn = false); - const main = MainView.Instance; Doc.SetSelectedTool(InkTool.None); var doDeselect = true; - if (main.isPointerDown) { + if (SnappingManager.GetIsDragging()) { DragManager.AbortDrag(); + } else if (CollectionDockingView.Instance.HasFullScreen) { + CollectionDockingView.Instance.CloseFullScreen(); } else { - if (CollectionDockingView.Instance.HasFullScreen()) { - CollectionDockingView.Instance.CloseFullScreen(); - } else { - doDeselect = !ContextMenu.Instance.closeMenu(); - } + doDeselect = !ContextMenu.Instance.closeMenu(); } doDeselect && SelectionManager.DeselectAll(); DictationManager.Controls.stop(); @@ -113,30 +108,18 @@ export default class KeyManager { break; case "delete": case "backspace": - if (document.activeElement) { - if (document.activeElement.tagName === "INPUT" || document.activeElement.tagName === "TEXTAREA") { - return { stopPropagation: false, preventDefault: false }; - } + if (document.activeElement?.tagName === "INPUT" || document.activeElement?.tagName === "TEXTAREA") { + return { stopPropagation: false, preventDefault: false }; } const selected = SelectionManager.SelectedDocuments().slice(); - UndoManager.RunInBatch(() => { - selected.map(dv => dv.props.removeDocument?.(dv.props.Document)); - }, "delete"); + UndoManager.RunInBatch(() => selected.map(dv => dv.props.removeDocument?.(dv.props.Document)), "delete"); SelectionManager.DeselectAll(); break; - case "arrowleft": - UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(-1, 0)), "nudge left"); - break; - case "arrowright": - UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(1, 0)), "nudge right"); - break; - case "arrowup": - UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(0, -1)), "nudge up"); - break; - case "arrowdown": - UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(0, 1)), "nudge down"); - break; + case "arrowleft": UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(-1, 0)), "nudge left"); break; + case "arrowright": UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(1, 0)), "nudge right"); break; + case "arrowup": UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(0, -1)), "nudge up"); break; + case "arrowdown": UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(0, 1)), "nudge down"); break; } return { @@ -150,22 +133,10 @@ export default class KeyManager { const preventDefault = false; switch (keyname) { - // case "~": - // DictationManager.Controls.listen({ useOverlay: true, tryExecute: true }); - // stopPropagation = true; - // preventDefault = true; - case "arrowleft": - UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(-10, 0)), "nudge left"); - break; - case "arrowright": - UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(10, 0)), "nudge right"); - break; - case "arrowup": - UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(0, -10)), "nudge up"); - break; - case "arrowdown": - UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(0, 10)), "nudge down"); - break; + case "arrowleft": UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(-10, 0)), "nudge left"); break; + case "arrowright": UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(10, 0)), "nudge right"); break; + case "arrowup": UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(0, -10)), "nudge up"); break; + case "arrowdown": UndoManager.RunInBatch(() => SelectionManager.SelectedDocuments().map(dv => dv.props.nudge?.(0, 10)), "nudge down"); break; } return { @@ -204,55 +175,32 @@ export default class KeyManager { switch (keyname) { case "arrowright": - if (document.activeElement) { - if (document.activeElement.tagName === "INPUT" || document.activeElement.tagName === "TEXTAREA") { - return { stopPropagation: false, preventDefault: false }; - } + if (document.activeElement?.tagName === "INPUT" || document.activeElement?.tagName === "TEXTAREA") { + return { stopPropagation: false, preventDefault: false }; } - MainView.Instance.mainFreeform && CollectionDockingView.AddRightSplit(MainView.Instance.mainFreeform); + MainView.Instance.mainFreeform && CollectionDockingView.AddSplit(MainView.Instance.mainFreeform, "right"); break; case "arrowleft": - if (document.activeElement) { - if (document.activeElement.tagName === "INPUT" || document.activeElement.tagName === "TEXTAREA") { - return { stopPropagation: false, preventDefault: false }; - } + if (document.activeElement?.tagName === "INPUT" || document.activeElement?.tagName === "TEXTAREA") { + return { stopPropagation: false, preventDefault: false }; } - MainView.Instance.mainFreeform && CollectionDockingView.CloseRightSplit(MainView.Instance.mainFreeform); + MainView.Instance.mainFreeform && CollectionDockingView.CloseSplit(MainView.Instance.mainFreeform); break; case "backspace": - if (document.activeElement) { - if (document.activeElement.tagName === "INPUT" || document.activeElement.tagName === "TEXTAREA") { - return { stopPropagation: false, preventDefault: false }; - } + if (document.activeElement?.tagName === "INPUT" || document.activeElement?.tagName === "TEXTAREA") { + return { stopPropagation: false, preventDefault: false }; } break; case "t": PromiseValue(Cast(Doc.UserDoc()["tabs-button-tools"], Doc)).then(pv => pv && (pv.onClick as ScriptField).script.run({ this: pv })); - if (MainView.Instance.flyoutWidth === 240) { - MainView.Instance.flyoutWidth = 0; - } else { - MainView.Instance.flyoutWidth = 240; - } - break; - case "l": - PromiseValue(Cast(Doc.UserDoc()["tabs-button-library"], Doc)).then(pv => pv && (pv.onClick as ScriptField).script.run({ this: pv })); - if (MainView.Instance.flyoutWidth === 250) { - MainView.Instance.flyoutWidth = 0; - } else { - MainView.Instance.flyoutWidth = 250; - } break; case "f": - PromiseValue(Cast(Doc.UserDoc()["tabs-button-search"], Doc)).then(pv => pv && (pv.onClick as ScriptField).script.run({ this: pv })); - if (MainView.Instance.flyoutWidth === 400) { - MainView.Instance.flyoutWidth = 0; - } else { - MainView.Instance.flyoutWidth = 400; - } + SearchBox.Instance._searchFullDB = "My Stuff"; + SearchBox.Instance.enter(undefined); break; case "o": const target = SelectionManager.SelectedDocuments()[0]; - target && CollectionDockingView.Instance && CollectionDockingView.Instance.OpenFullScreen(target); + target && CollectionDockingView.OpenFullScreen(target.props.Document); break; case "r": preventDefault = false; @@ -323,8 +271,6 @@ export default class KeyManager { undoBatch(() => { targetDataDoc[fieldKey] = new List<Doc>([...docList, ...added]); targetDataDoc[fieldKey + "-lastModified"] = new DateField(new Date(Date.now())); - const lastModified = "lastModified"; - targetDataDoc[lastModified] = new DateField(new Date(Date.now())); })(); } } |