Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/app/sidebar/right.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
);
}
Expand Down
24 changes: 18 additions & 6 deletions src/app/workspace/cmdinput/textareainput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

Expand Down Expand Up @@ -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") {
Expand All @@ -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(
Expand Down Expand Up @@ -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;
});
Expand All @@ -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;
});
Expand All @@ -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;
});
}
Expand Down
47 changes: 44 additions & 3 deletions src/util/keyutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -67,6 +68,7 @@ class KeybindManager {
});
this.globalModel = GlobalModel;
this.initKeyDescriptionsMap();
this.lastKeyData = { domain: "none", keyPress: "none" };
}

initKeyDescriptionsMap() {
Expand Down Expand Up @@ -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 += "⌘";
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -330,7 +348,7 @@ class KeybindManager {
}

getActiveKeybindsVersion() {
return this.activeKeybindsVersion.get();
return this.activeKeybindsVersion;
}

checkKeyInKeybinding(key: string, keyDescription: string) {
Expand Down Expand Up @@ -398,6 +416,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> }> = [];
Expand Down Expand Up @@ -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) {
Expand Down