mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-21 21:32:13 +01:00
Debug pane and lookup key (#518)
* added new util functions for logging keyutils and added debug pane * clean up the formatting
This commit is contained in:
parent
052645e0df
commit
3be96c949d
@ -25,4 +25,29 @@
|
|||||||
&.collapsed {
|
&.collapsed {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.keybind-debug-pane {
|
||||||
|
padding: 10px;
|
||||||
|
overflow: hidden;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
.keybind-pane-title {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: bold;
|
||||||
|
padding-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.keybind-level {
|
||||||
|
margin-top: 10px;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.keybind-domain {
|
||||||
|
font-size: 14px;
|
||||||
|
margin-left: 20px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as mobxReact from "mobx-react";
|
import * as mobxReact from "mobx-react";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
import { If, For } from "tsx-control-statements/components";
|
||||||
|
|
||||||
import localizedFormat from "dayjs/plugin/localizedFormat";
|
import localizedFormat from "dayjs/plugin/localizedFormat";
|
||||||
import { GlobalModel } from "@/models";
|
import { GlobalModel } from "@/models";
|
||||||
@ -17,6 +18,34 @@ interface RightSideBarProps {
|
|||||||
parentRef: React.RefObject<HTMLElement>;
|
parentRef: React.RefObject<HTMLElement>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@mobxReact.observer
|
||||||
|
class KeybindDevPane extends React.Component<{}, {}> {
|
||||||
|
render() {
|
||||||
|
let curActiveKeybinds: Array<{ name: string; domains: Array<string> }> =
|
||||||
|
GlobalModel.keybindManager.getActiveKeybindings();
|
||||||
|
let keybindLevel: { name: string; domains: Array<string> } = null;
|
||||||
|
let domain: string = null;
|
||||||
|
let curVersion = GlobalModel.keybindManager.getActiveKeybindsVersion();
|
||||||
|
let levelIdx: number = 0;
|
||||||
|
let domainIdx: number = 0;
|
||||||
|
return (
|
||||||
|
<div className="keybind-debug-pane">
|
||||||
|
<div className="keybind-pane-title">Keybind Manager</div>
|
||||||
|
<For index="levelIdx" each="keybindLevel" of={curActiveKeybinds}>
|
||||||
|
<div className="keybind-level" key={"level-" + curVersion + levelIdx}>
|
||||||
|
{keybindLevel.name}
|
||||||
|
</div>
|
||||||
|
<For index="domainIdx" each="domain" of={keybindLevel.domains}>
|
||||||
|
<div className="keybind-domain" key={"domain-" + curVersion + domainIdx}>
|
||||||
|
{domain}
|
||||||
|
</div>
|
||||||
|
</For>
|
||||||
|
</For>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@mobxReact.observer
|
@mobxReact.observer
|
||||||
class RightSideBar extends React.Component<RightSideBarProps, {}> {
|
class RightSideBar extends React.Component<RightSideBarProps, {}> {
|
||||||
render() {
|
render() {
|
||||||
@ -35,6 +64,9 @@ class RightSideBar extends React.Component<RightSideBarProps, {}> {
|
|||||||
<i className="fa-sharp fa-regular fa-xmark"></i>
|
<i className="fa-sharp fa-regular fa-xmark"></i>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
<If condition={GlobalModel.isDev}>
|
||||||
|
<KeybindDevPane></KeybindDevPane>
|
||||||
|
</If>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)}
|
)}
|
||||||
</ResizableSidebar>
|
</ResizableSidebar>
|
||||||
|
@ -49,6 +49,7 @@ class KeybindManager {
|
|||||||
userKeybindings: KeybindConfigArray;
|
userKeybindings: KeybindConfigArray;
|
||||||
userKeybindingError: OV<string>;
|
userKeybindingError: OV<string>;
|
||||||
globalModel: any;
|
globalModel: any;
|
||||||
|
activeKeybindsVersion: OV<number>;
|
||||||
|
|
||||||
constructor(GlobalModel: any) {
|
constructor(GlobalModel: any) {
|
||||||
this.levelMap = new Map();
|
this.levelMap = new Map();
|
||||||
@ -59,7 +60,10 @@ class KeybindManager {
|
|||||||
this.levelMap.set(curLevel, new Array<Keybind>());
|
this.levelMap.set(curLevel, new Array<Keybind>());
|
||||||
}
|
}
|
||||||
this.userKeybindingError = mobx.observable.box(null, {
|
this.userKeybindingError = mobx.observable.box(null, {
|
||||||
name: "keyutil-userKeybindingError",
|
name: "keybindManager-userKeybindingError",
|
||||||
|
});
|
||||||
|
this.activeKeybindsVersion = mobx.observable.box(0, {
|
||||||
|
name: "keybindManager-activeKeybindsVersion",
|
||||||
});
|
});
|
||||||
this.globalModel = GlobalModel;
|
this.globalModel = GlobalModel;
|
||||||
this.initKeyDescriptionsMap();
|
this.initKeyDescriptionsMap();
|
||||||
@ -314,6 +318,100 @@ class KeybindManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getActiveKeybindsVersion() {
|
||||||
|
return this.activeKeybindsVersion.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
checkKeyInKeybinding(key: string, keyDescription: string) {
|
||||||
|
if (keyDescription == "any") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!this.keyDescriptionsMap.has(keyDescription)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let keyPressArray = this.keyDescriptionsMap.get(keyDescription).keys;
|
||||||
|
for (let index = 0; index < keyPressArray.length; index++) {
|
||||||
|
let curKeyPress = keyPressArray[index];
|
||||||
|
if (keybindingIsEqual(key, curKeyPress)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
lookupKeyInLevel(key: string, level: Array<Keybind>): Array<Keybind> {
|
||||||
|
let toReturn: Array<Keybind> = [];
|
||||||
|
for (let index = level.length - 1; index >= 0; index--) {
|
||||||
|
let curKeybind = level[index];
|
||||||
|
console.log("index", index, "curKeybind: ", curKeybind);
|
||||||
|
if (this.checkKeyInKeybinding(key, curKeybind.keybinding)) {
|
||||||
|
toReturn.push({ ...curKeybind }); // shallow copy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
lookupKey(key: string) {
|
||||||
|
let modalLevel = this.levelMap.get("modal");
|
||||||
|
let toReturn: Array<Keybind> = [];
|
||||||
|
if (modalLevel.length != 0) {
|
||||||
|
let controlLevel = this.levelMap.get("control");
|
||||||
|
toReturn = toReturn.concat(this.lookupKeyInLevel(key, controlLevel));
|
||||||
|
toReturn = toReturn.concat(this.lookupKeyInLevel(key, modalLevel));
|
||||||
|
let systemLevel = this.levelMap.get("system");
|
||||||
|
toReturn = toReturn.concat(this.lookupKeyInLevel(key, systemLevel));
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
for (let index = this.levelArray.length - 1; index >= 0; index--) {
|
||||||
|
let curLevel = this.levelArray[index];
|
||||||
|
let curKeybindsArray;
|
||||||
|
if (this.levelMap.has(curLevel)) {
|
||||||
|
curKeybindsArray = this.levelMap.get(curLevel);
|
||||||
|
} else {
|
||||||
|
console.error("error processing key event: couldn't find level: ", curLevel);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
toReturn = toReturn.concat(this.lookupKeyInLevel(key, curKeybindsArray));
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
getDomainListForLevel(level: Array<Keybind>): Array<string> {
|
||||||
|
let toReturn: Array<string> = [];
|
||||||
|
for (let index = 0; index < level.length; index++) {
|
||||||
|
let curDomain = level[index].domain;
|
||||||
|
if (!toReturn.includes(curDomain)) {
|
||||||
|
toReturn.push(curDomain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
getActiveKeybindings(): Array<{ name: string; domains: Array<string> }> {
|
||||||
|
let modalLevel = this.levelMap.get("modal");
|
||||||
|
let toReturn: Array<{ name: string; domains: Array<string> }> = [];
|
||||||
|
if (modalLevel.length != 0) {
|
||||||
|
let controlLevel = this.levelMap.get("control");
|
||||||
|
toReturn.push({ name: "control", domains: this.getDomainListForLevel(controlLevel) });
|
||||||
|
toReturn.push({ name: "modal", domains: this.getDomainListForLevel(modalLevel) });
|
||||||
|
let systemLevel = this.levelMap.get("system");
|
||||||
|
toReturn.push({ name: "system", domains: this.getDomainListForLevel(systemLevel) });
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
for (let index = this.levelArray.length - 1; index >= 0; index--) {
|
||||||
|
let curLevel = this.levelArray[index];
|
||||||
|
let curKeybindsArray;
|
||||||
|
if (this.levelMap.has(curLevel)) {
|
||||||
|
curKeybindsArray = this.levelMap.get(curLevel);
|
||||||
|
} else {
|
||||||
|
console.error("error processing key event: couldn't find level: ", curLevel);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
toReturn.push({ name: curLevel, domains: this.getDomainListForLevel(curKeybindsArray) });
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
registerKeybinding(level: string, domain: string, keybinding: string, callback: KeybindCallback): boolean {
|
registerKeybinding(level: string, domain: string, keybinding: string, callback: KeybindCallback): boolean {
|
||||||
if (domain == "" || this.keybindingAlreadyAdded(level, domain, keybinding)) {
|
if (domain == "" || this.keybindingAlreadyAdded(level, domain, keybinding)) {
|
||||||
return false;
|
return false;
|
||||||
@ -326,6 +424,9 @@ class KeybindManager {
|
|||||||
let curKeybindArray = this.levelMap.get(level);
|
let curKeybindArray = this.levelMap.get(level);
|
||||||
curKeybindArray.push(newKeybind);
|
curKeybindArray.push(newKeybind);
|
||||||
this.levelMap.set(level, curKeybindArray);
|
this.levelMap.set(level, curKeybindArray);
|
||||||
|
mobx.action(() => {
|
||||||
|
this.activeKeybindsVersion.set(this.activeKeybindsVersion.get() + 1);
|
||||||
|
})();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,9 +472,12 @@ class KeybindManager {
|
|||||||
keybindsArray.splice(index, 1);
|
keybindsArray.splice(index, 1);
|
||||||
index--;
|
index--;
|
||||||
this.levelMap.set(level, keybindsArray);
|
this.levelMap.set(level, keybindsArray);
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
mobx.action(() => {
|
||||||
|
this.activeKeybindsVersion.set(this.activeKeybindsVersion.get() + 1);
|
||||||
|
})();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,6 +496,9 @@ class KeybindManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.domainCallbacks.delete(domain);
|
this.domainCallbacks.delete(domain);
|
||||||
|
mobx.action(() => {
|
||||||
|
this.activeKeybindsVersion.set(this.activeKeybindsVersion.get() + 1);
|
||||||
|
})();
|
||||||
return foundKeybind;
|
return foundKeybind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user