From c74380b187a522634290429f3947c7fb1422bd58 Mon Sep 17 00:00:00 2001 From: MrStashley Date: Fri, 29 Mar 2024 10:47:59 -0700 Subject: [PATCH 1/4] added more cmdinput-anykey behavior --- src/app/workspace/cmdinput/textareainput.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/app/workspace/cmdinput/textareainput.tsx b/src/app/workspace/cmdinput/textareainput.tsx index f553780c60..d17b30addf 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; @@ -215,9 +215,7 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput } return true; }); keybindManager.registerDomainCallback("cmdinput", (waveEvent) => { - if (!keybindManager.checkKeyPressed(waveEvent, "cmdinput:autocomplete")) { - this.lastTab = false; - } + inputObject.handleCmdInputAnyKey(waveEvent); return false; }); } @@ -418,6 +416,13 @@ class TextAreaInput extends React.Component<{ screen: Screen; onHeightChange: () GlobalModel.inputModel.setCurLine(currentRef.value); } + handleCmdInputAnyKey(waveEvent: WaveKeyboardEvent) { + if (!GlobalModel.keybindManager.checkKeyPressed(waveEvent, "cmdinput:autocomplete")) { + this.lastTab = false; + } + this.lastHistoryUpDown = false; + } + @mobx.action @boundMethod onKeyDown(e: any) {} From 2ae8138c6dcd3398018ed581f14c782b5a207b6f Mon Sep 17 00:00:00 2001 From: MrStashley Date: Fri, 29 Mar 2024 11:11:00 -0700 Subject: [PATCH 2/4] fixed lasthistoryupdown --- src/app/workspace/cmdinput/textareainput.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/workspace/cmdinput/textareainput.tsx b/src/app/workspace/cmdinput/textareainput.tsx index d17b30addf..553eec8c9b 100644 --- a/src/app/workspace/cmdinput/textareainput.tsx +++ b/src/app/workspace/cmdinput/textareainput.tsx @@ -420,7 +420,16 @@ class TextAreaInput extends React.Component<{ screen: Screen; onHeightChange: () if (!GlobalModel.keybindManager.checkKeyPressed(waveEvent, "cmdinput:autocomplete")) { this.lastTab = false; } - this.lastHistoryUpDown = false; + if ( + !GlobalModel.keybindManager.checkKeysPressed(waveEvent, [ + "generic:selectAbove", + "generic:selectBelow", + "generic:selectPageAbove", + "generic:selectPageBelow", + ]) + ) { + this.lastHistoryUpDown = false; + } } @mobx.action From 3e51db2c481190eebdf3e179967e32c297677718 Mon Sep 17 00:00:00 2001 From: MrStashley Date: Fri, 29 Mar 2024 11:19:44 -0700 Subject: [PATCH 3/4] more bug fixes --- src/app/workspace/cmdinput/textareainput.tsx | 33 ++++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/app/workspace/cmdinput/textareainput.tsx b/src/app/workspace/cmdinput/textareainput.tsx index 553eec8c9b..2c48065483 100644 --- a/src/app/workspace/cmdinput/textareainput.tsx +++ b/src/app/workspace/cmdinput/textareainput.tsx @@ -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) => { + this.curPress = "historyupdown"; inputObject.arrowUpPressed(); return true; }); keybindManager.registerKeybinding("pane", "cmdinput", "generic:selectBelow", (waveEvent) => { + this.curPress = "historyupdown"; inputObject.arrowDownPressed(); return true; }); 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,7 +223,14 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput } return true; }); keybindManager.registerDomainCallback("cmdinput", (waveEvent) => { - inputObject.handleCmdInputAnyKey(waveEvent); + console.log("curPress:", this.curPress); + if (this.curPress != "tab") { + this.lastTab = false; + } + if (this.curPress != "historyupdown") { + inputObject.lastHistoryUpDown = false; + } + this.curPress = ""; return false; }); } @@ -416,22 +431,6 @@ class TextAreaInput extends React.Component<{ screen: Screen; onHeightChange: () GlobalModel.inputModel.setCurLine(currentRef.value); } - handleCmdInputAnyKey(waveEvent: WaveKeyboardEvent) { - if (!GlobalModel.keybindManager.checkKeyPressed(waveEvent, "cmdinput:autocomplete")) { - this.lastTab = false; - } - if ( - !GlobalModel.keybindManager.checkKeysPressed(waveEvent, [ - "generic:selectAbove", - "generic:selectBelow", - "generic:selectPageAbove", - "generic:selectPageBelow", - ]) - ) { - this.lastHistoryUpDown = false; - } - } - @mobx.action @boundMethod onKeyDown(e: any) {} From 4028dde75dde7553f7e7455a53f188f66e55c614 Mon Sep 17 00:00:00 2001 From: MrStashley Date: Fri, 29 Mar 2024 11:56:39 -0700 Subject: [PATCH 4/4] fixed history bugs hopefully fully fixed --- src/app/sidebar/right.tsx | 9 +++- src/app/workspace/cmdinput/textareainput.tsx | 9 ++-- src/util/keyutil.ts | 47 ++++++++++++++++++-- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/app/sidebar/right.tsx b/src/app/sidebar/right.tsx index f87f1f8977..26191c3fb1 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 2c48065483..e62ee4ab8f 100644 --- a/src/app/workspace/cmdinput/textareainput.tsx +++ b/src/app/workspace/cmdinput/textareainput.tsx @@ -200,13 +200,13 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput } }); keybindManager.registerKeybinding("pane", "cmdinput", "generic:selectAbove", (waveEvent) => { this.curPress = "historyupdown"; - inputObject.arrowUpPressed(); - return true; + let rtn = inputObject.arrowUpPressed(); + return rtn; }); keybindManager.registerKeybinding("pane", "cmdinput", "generic:selectBelow", (waveEvent) => { this.curPress = "historyupdown"; - inputObject.arrowDownPressed(); - return true; + let rtn = inputObject.arrowDownPressed(); + return rtn; }); keybindManager.registerKeybinding("pane", "cmdinput", "generic:selectPageAbove", (waveEvent) => { this.curPress = "historyupdown"; @@ -223,7 +223,6 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput } return true; }); keybindManager.registerDomainCallback("cmdinput", (waveEvent) => { - console.log("curPress:", this.curPress); if (this.curPress != "tab") { this.lastTab = false; } diff --git a/src/util/keyutil.ts b/src/util/keyutil.ts index c70f67e0b5..f93b11850f 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; } @@ -330,7 +348,7 @@ class KeybindManager { } getActiveKeybindsVersion() { - return this.activeKeybindsVersion.get(); + return this.activeKeybindsVersion; } checkKeyInKeybinding(key: string, keyDescription: string) { @@ -398,6 +416,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 }> = []; @@ -601,6 +623,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) {