Added this.lastHistoryUpDown = false to cmdinput domain callback (#533)

* added more cmdinput-anykey behavior

* fixed lasthistoryupdown

* more bug fixes

* fixed history bugs hopefully fully fixed
This commit is contained in:
Cole Lashley
2024-03-29 13:28:49 -07:00
committed by GitHub
parent 0024f0f3e8
commit f41ac1d5e3
3 changed files with 70 additions and 10 deletions
+8 -1
View File
@@ -25,9 +25,10 @@ class KeybindDevPane extends React.Component<{}, {}> {
GlobalModel.keybindManager.getActiveKeybindings();
let keybindLevel: { name: string; domains: Array<string> } = 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 (
<div className="keybind-debug-pane">
<div className="keybind-pane-title">Keybind Manager</div>
@@ -41,6 +42,12 @@ class KeybindDevPane extends React.Component<{}, {}> {
</div>
</For>
</For>
<br />
<br />
<div>
<h1>Last KeyPress Domain: {lastKeyData.domain}</h1>
<h1>Last KeyPress key: {lastKeyData.keyPress}</h1>
</div>
</div>
);
}
+18 -6
View File
@@ -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<T> = mobx.IObservableValue<T>;
@@ -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;
});
}
+44 -3
View File
@@ -50,6 +50,7 @@ class KeybindManager {
userKeybindingError: OV<string>;
globalModel: any;
activeKeybindsVersion: OV<number>;
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<string> }> {
let modalLevel = this.levelMap.get("modal");
let toReturn: Array<{ name: string; domains: Array<string> }> = [];
@@ -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) {