diff --git a/src/app/sidebar/right.tsx b/src/app/sidebar/right.tsx index f87f1f89..26191c3f 100644 --- a/src/app/sidebar/right.tsx +++ b/src/app/sidebar/right.tsx @@ -25,9 +25,10 @@ class KeybindDevPane extends React.Component<{}, {}> { GlobalModel.keybindManager.getActiveKeybindings(); let keybindLevel: { name: string; domains: Array } = null; let domain: string = null; - let curVersion = GlobalModel.keybindManager.getActiveKeybindsVersion(); + let curVersion = GlobalModel.keybindManager.getActiveKeybindsVersion().get(); let levelIdx: number = 0; let domainIdx: number = 0; + let lastKeyData = GlobalModel.keybindManager.getLastKeyData(); return (
Keybind Manager
@@ -41,6 +42,12 @@ class KeybindDevPane extends React.Component<{}, {}> {
+
+
+
+

Last KeyPress Domain: {lastKeyData.domain}

+

Last KeyPress key: {lastKeyData.keyPress}

+
); } diff --git a/src/app/workspace/cmdinput/textareainput.tsx b/src/app/workspace/cmdinput/textareainput.tsx index f553780c..e62ee4ab 100644 --- a/src/app/workspace/cmdinput/textareainput.tsx +++ b/src/app/workspace/cmdinput/textareainput.tsx @@ -11,7 +11,7 @@ import cn from "classnames"; import { GlobalModel, GlobalCommandRunner, Screen } from "@/models"; import { getMonoFontSize } from "@/util/textmeasure"; import * as appconst from "@/app/appconst"; -import { checkKeyPressed, adaptFromReactOrNativeKeyEvent } from "@/util/keyutil"; +import { checkKeyPressed, adaptFromReactOrNativeKeyEvent, WaveKeyboardEvent } from "@/util/keyutil"; type OV = mobx.IObservableValue; @@ -103,6 +103,7 @@ class HistoryKeybindings extends React.Component<{ inputObject: TextAreaInput }, class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput }, {}> { lastTab: boolean; + curPress: string; componentDidMount() { if (GlobalModel.activeMainView != "session") { @@ -115,6 +116,7 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput } keybindManager.registerKeybinding("pane", "cmdinput", "cmdinput:autocomplete", (waveEvent) => { let lastTab = this.lastTab; this.lastTab = true; + this.curPress = "tab"; let curLine = inputModel.getCurLine(); if (lastTab) { GlobalModel.submitCommand( @@ -183,10 +185,12 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput } return true; }); keybindManager.registerKeybinding("pane", "cmdinput", "cmdinput:previousHistoryItem", (waveEvent) => { + this.curPress = "historyupdown"; inputObject.controlP(); return true; }); keybindManager.registerKeybinding("pane", "cmdinput", "cmdinput:nextHistoryItem", (waveEvent) => { + this.curPress = "historyupdown"; inputObject.controlN(); return true; }); @@ -195,18 +199,22 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput } return true; }); keybindManager.registerKeybinding("pane", "cmdinput", "generic:selectAbove", (waveEvent) => { - inputObject.arrowUpPressed(); - return true; + this.curPress = "historyupdown"; + let rtn = inputObject.arrowUpPressed(); + return rtn; }); keybindManager.registerKeybinding("pane", "cmdinput", "generic:selectBelow", (waveEvent) => { - inputObject.arrowDownPressed(); - return true; + this.curPress = "historyupdown"; + let rtn = inputObject.arrowDownPressed(); + return rtn; }); keybindManager.registerKeybinding("pane", "cmdinput", "generic:selectPageAbove", (waveEvent) => { + this.curPress = "historyupdown"; inputObject.scrollPage(true); return true; }); keybindManager.registerKeybinding("pane", "cmdinput", "generic:selectPageBelow", (waveEvent) => { + this.curPress = "historyupdown"; inputObject.scrollPage(false); return true; }); @@ -215,9 +223,13 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput } return true; }); keybindManager.registerDomainCallback("cmdinput", (waveEvent) => { - if (!keybindManager.checkKeyPressed(waveEvent, "cmdinput:autocomplete")) { + if (this.curPress != "tab") { this.lastTab = false; } + if (this.curPress != "historyupdown") { + inputObject.lastHistoryUpDown = false; + } + this.curPress = ""; return false; }); } diff --git a/src/util/keyutil.ts b/src/util/keyutil.ts index 7f0bfe69..16752f44 100644 --- a/src/util/keyutil.ts +++ b/src/util/keyutil.ts @@ -50,6 +50,7 @@ class KeybindManager { userKeybindingError: OV; globalModel: any; activeKeybindsVersion: OV; + lastKeyData: { domain: string; keyPress: string }; constructor(GlobalModel: any) { this.levelMap = new Map(); @@ -67,6 +68,7 @@ class KeybindManager { }); this.globalModel = GlobalModel; this.initKeyDescriptionsMap(); + this.lastKeyData = { domain: "none", keyPress: "none" }; } initKeyDescriptionsMap() { @@ -127,8 +129,7 @@ class KeybindManager { this.keyDescriptionsMap = newKeyDescriptions; } - prettyPrintKeybind(keyDescription: string): string { - let keyPress = parseKeyDescription(keyDescription); + prettyPrintKeyPress(keyPress: KeyPressDecl): string { let returnString = ""; if (keyPress.mods.Cmd) { returnString += "⌘"; @@ -152,6 +153,11 @@ class KeybindManager { return returnString; } + prettyPrintKeybind(keyDescription: string): string { + let keyPress = parseKeyDescription(keyDescription); + return this.prettyPrintKeyPress(keyPress); + } + getUIDescription(keyDescription: string, prettyPrint: boolean = true): KeybindConfig { let keybinds = this.getKeybindsFromDescription(keyDescription, prettyPrint); if (!this.keyDescriptionsMap.has(keyDescription)) { @@ -268,11 +274,23 @@ class KeybindManager { if (shouldReturn) { nativeEvent.preventDefault(); nativeEvent.stopPropagation(); + this.lastKeyData.domain = curKeybind.domain; + this.lastKeyData.keyPress = this.prettyPrintKeyPress( + getKeyPressDeclFromKeyboardEvent(event, KeyTypeKey) + ); + mobx.action(() => { + this.activeKeybindsVersion.set(this.activeKeybindsVersion.get() + 1); + })(); this.runDomainCallbacks(event, domainCallbacksToRun); return true; } } } + this.lastKeyData.domain = "none"; + this.lastKeyData.keyPress = "none"; + mobx.action(() => { + this.activeKeybindsVersion.set(this.activeKeybindsVersion.get() + 1); + })(); this.runDomainCallbacks(event, domainCallbacksToRun); return false; } @@ -373,7 +391,7 @@ class KeybindManager { } getActiveKeybindsVersion() { - return this.activeKeybindsVersion.get(); + return this.activeKeybindsVersion; } checkKeyInKeybinding(key: string, keyDescription: string) { @@ -441,6 +459,10 @@ class KeybindManager { return toReturn; } + getLastKeyData() { + return this.lastKeyData; + } + getActiveKeybindings(): Array<{ name: string; domains: Array }> { let modalLevel = this.levelMap.get("modal"); let toReturn: Array<{ name: string; domains: Array }> = []; @@ -644,6 +666,25 @@ function parseKeyDescription(keyDescription: string): KeyPressDecl { return rtn; } +function getKeyPressDeclFromKeyboardEvent(waveEvent: WaveKeyboardEvent, keyType: string): KeyPressDecl { + let rtn = { key: "", mods: {} } as KeyPressDecl; + rtn.mods.Cmd = waveEvent.cmd; + rtn.mods.Ctrl = waveEvent.control; + rtn.mods.Shift = waveEvent.shift; + rtn.mods.Option = waveEvent.option; + rtn.mods.Alt = waveEvent.alt && !waveEvent.option; + rtn.mods.Meta = waveEvent.meta && !waveEvent.cmd; + if (keyType == KeyTypeKey) { + rtn.key = waveEvent.code; + rtn.keyType = KeyTypeKey; + } + if (keyType == KeyTypeCode) { + rtn.key = waveEvent.code; + rtn.keyType = KeyTypeCode; + } + return rtn; +} + function parseKey(key: string): { key: string; type: string } { let regexMatch = key.match(KeyTypeCodeRegex); if (regexMatch != null && regexMatch.length > 1) {