Skip to content

Commit f41ac1d

Browse files
authored
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
1 parent 0024f0f commit f41ac1d

3 files changed

Lines changed: 70 additions & 10 deletions

File tree

src/app/sidebar/right.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ class KeybindDevPane extends React.Component<{}, {}> {
2525
GlobalModel.keybindManager.getActiveKeybindings();
2626
let keybindLevel: { name: string; domains: Array<string> } = null;
2727
let domain: string = null;
28-
let curVersion = GlobalModel.keybindManager.getActiveKeybindsVersion();
28+
let curVersion = GlobalModel.keybindManager.getActiveKeybindsVersion().get();
2929
let levelIdx: number = 0;
3030
let domainIdx: number = 0;
31+
let lastKeyData = GlobalModel.keybindManager.getLastKeyData();
3132
return (
3233
<div className="keybind-debug-pane">
3334
<div className="keybind-pane-title">Keybind Manager</div>
@@ -41,6 +42,12 @@ class KeybindDevPane extends React.Component<{}, {}> {
4142
</div>
4243
</For>
4344
</For>
45+
<br />
46+
<br />
47+
<div>
48+
<h1>Last KeyPress Domain: {lastKeyData.domain}</h1>
49+
<h1>Last KeyPress key: {lastKeyData.keyPress}</h1>
50+
</div>
4451
</div>
4552
);
4653
}

src/app/workspace/cmdinput/textareainput.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import cn from "classnames";
1111
import { GlobalModel, GlobalCommandRunner, Screen } from "@/models";
1212
import { getMonoFontSize } from "@/util/textmeasure";
1313
import * as appconst from "@/app/appconst";
14-
import { checkKeyPressed, adaptFromReactOrNativeKeyEvent } from "@/util/keyutil";
14+
import { checkKeyPressed, adaptFromReactOrNativeKeyEvent, WaveKeyboardEvent } from "@/util/keyutil";
1515

1616
type OV<T> = mobx.IObservableValue<T>;
1717

@@ -103,6 +103,7 @@ class HistoryKeybindings extends React.Component<{ inputObject: TextAreaInput },
103103

104104
class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput }, {}> {
105105
lastTab: boolean;
106+
curPress: string;
106107

107108
componentDidMount() {
108109
if (GlobalModel.activeMainView != "session") {
@@ -115,6 +116,7 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput }
115116
keybindManager.registerKeybinding("pane", "cmdinput", "cmdinput:autocomplete", (waveEvent) => {
116117
let lastTab = this.lastTab;
117118
this.lastTab = true;
119+
this.curPress = "tab";
118120
let curLine = inputModel.getCurLine();
119121
if (lastTab) {
120122
GlobalModel.submitCommand(
@@ -183,10 +185,12 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput }
183185
return true;
184186
});
185187
keybindManager.registerKeybinding("pane", "cmdinput", "cmdinput:previousHistoryItem", (waveEvent) => {
188+
this.curPress = "historyupdown";
186189
inputObject.controlP();
187190
return true;
188191
});
189192
keybindManager.registerKeybinding("pane", "cmdinput", "cmdinput:nextHistoryItem", (waveEvent) => {
193+
this.curPress = "historyupdown";
190194
inputObject.controlN();
191195
return true;
192196
});
@@ -195,18 +199,22 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput }
195199
return true;
196200
});
197201
keybindManager.registerKeybinding("pane", "cmdinput", "generic:selectAbove", (waveEvent) => {
198-
inputObject.arrowUpPressed();
199-
return true;
202+
this.curPress = "historyupdown";
203+
let rtn = inputObject.arrowUpPressed();
204+
return rtn;
200205
});
201206
keybindManager.registerKeybinding("pane", "cmdinput", "generic:selectBelow", (waveEvent) => {
202-
inputObject.arrowDownPressed();
203-
return true;
207+
this.curPress = "historyupdown";
208+
let rtn = inputObject.arrowDownPressed();
209+
return rtn;
204210
});
205211
keybindManager.registerKeybinding("pane", "cmdinput", "generic:selectPageAbove", (waveEvent) => {
212+
this.curPress = "historyupdown";
206213
inputObject.scrollPage(true);
207214
return true;
208215
});
209216
keybindManager.registerKeybinding("pane", "cmdinput", "generic:selectPageBelow", (waveEvent) => {
217+
this.curPress = "historyupdown";
210218
inputObject.scrollPage(false);
211219
return true;
212220
});
@@ -215,9 +223,13 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput }
215223
return true;
216224
});
217225
keybindManager.registerDomainCallback("cmdinput", (waveEvent) => {
218-
if (!keybindManager.checkKeyPressed(waveEvent, "cmdinput:autocomplete")) {
226+
if (this.curPress != "tab") {
219227
this.lastTab = false;
220228
}
229+
if (this.curPress != "historyupdown") {
230+
inputObject.lastHistoryUpDown = false;
231+
}
232+
this.curPress = "";
221233
return false;
222234
});
223235
}

src/util/keyutil.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class KeybindManager {
5050
userKeybindingError: OV<string>;
5151
globalModel: any;
5252
activeKeybindsVersion: OV<number>;
53+
lastKeyData: { domain: string; keyPress: string };
5354

5455
constructor(GlobalModel: any) {
5556
this.levelMap = new Map();
@@ -67,6 +68,7 @@ class KeybindManager {
6768
});
6869
this.globalModel = GlobalModel;
6970
this.initKeyDescriptionsMap();
71+
this.lastKeyData = { domain: "none", keyPress: "none" };
7072
}
7173

7274
initKeyDescriptionsMap() {
@@ -127,8 +129,7 @@ class KeybindManager {
127129
this.keyDescriptionsMap = newKeyDescriptions;
128130
}
129131

130-
prettyPrintKeybind(keyDescription: string): string {
131-
let keyPress = parseKeyDescription(keyDescription);
132+
prettyPrintKeyPress(keyPress: KeyPressDecl): string {
132133
let returnString = "";
133134
if (keyPress.mods.Cmd) {
134135
returnString += "⌘";
@@ -152,6 +153,11 @@ class KeybindManager {
152153
return returnString;
153154
}
154155

156+
prettyPrintKeybind(keyDescription: string): string {
157+
let keyPress = parseKeyDescription(keyDescription);
158+
return this.prettyPrintKeyPress(keyPress);
159+
}
160+
155161
getUIDescription(keyDescription: string, prettyPrint: boolean = true): KeybindConfig {
156162
let keybinds = this.getKeybindsFromDescription(keyDescription, prettyPrint);
157163
if (!this.keyDescriptionsMap.has(keyDescription)) {
@@ -268,11 +274,23 @@ class KeybindManager {
268274
if (shouldReturn) {
269275
nativeEvent.preventDefault();
270276
nativeEvent.stopPropagation();
277+
this.lastKeyData.domain = curKeybind.domain;
278+
this.lastKeyData.keyPress = this.prettyPrintKeyPress(
279+
getKeyPressDeclFromKeyboardEvent(event, KeyTypeKey)
280+
);
281+
mobx.action(() => {
282+
this.activeKeybindsVersion.set(this.activeKeybindsVersion.get() + 1);
283+
})();
271284
this.runDomainCallbacks(event, domainCallbacksToRun);
272285
return true;
273286
}
274287
}
275288
}
289+
this.lastKeyData.domain = "none";
290+
this.lastKeyData.keyPress = "none";
291+
mobx.action(() => {
292+
this.activeKeybindsVersion.set(this.activeKeybindsVersion.get() + 1);
293+
})();
276294
this.runDomainCallbacks(event, domainCallbacksToRun);
277295
return false;
278296
}
@@ -373,7 +391,7 @@ class KeybindManager {
373391
}
374392

375393
getActiveKeybindsVersion() {
376-
return this.activeKeybindsVersion.get();
394+
return this.activeKeybindsVersion;
377395
}
378396

379397
checkKeyInKeybinding(key: string, keyDescription: string) {
@@ -441,6 +459,10 @@ class KeybindManager {
441459
return toReturn;
442460
}
443461

462+
getLastKeyData() {
463+
return this.lastKeyData;
464+
}
465+
444466
getActiveKeybindings(): Array<{ name: string; domains: Array<string> }> {
445467
let modalLevel = this.levelMap.get("modal");
446468
let toReturn: Array<{ name: string; domains: Array<string> }> = [];
@@ -644,6 +666,25 @@ function parseKeyDescription(keyDescription: string): KeyPressDecl {
644666
return rtn;
645667
}
646668

669+
function getKeyPressDeclFromKeyboardEvent(waveEvent: WaveKeyboardEvent, keyType: string): KeyPressDecl {
670+
let rtn = { key: "", mods: {} } as KeyPressDecl;
671+
rtn.mods.Cmd = waveEvent.cmd;
672+
rtn.mods.Ctrl = waveEvent.control;
673+
rtn.mods.Shift = waveEvent.shift;
674+
rtn.mods.Option = waveEvent.option;
675+
rtn.mods.Alt = waveEvent.alt && !waveEvent.option;
676+
rtn.mods.Meta = waveEvent.meta && !waveEvent.cmd;
677+
if (keyType == KeyTypeKey) {
678+
rtn.key = waveEvent.code;
679+
rtn.keyType = KeyTypeKey;
680+
}
681+
if (keyType == KeyTypeCode) {
682+
rtn.key = waveEvent.code;
683+
rtn.keyType = KeyTypeCode;
684+
}
685+
return rtn;
686+
}
687+
647688
function parseKey(key: string): { key: string; type: string } {
648689
let regexMatch = key.match(KeyTypeCodeRegex);
649690
if (regexMatch != null && regexMatch.length > 1) {

0 commit comments

Comments
 (0)