mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
Cmdinput keybinding bug fixes (#524)
* added domain callback for every layer * added domain callback for every layer * switched dump logs to false * dropdown fixes * moved uuid back to constructor
This commit is contained in:
parent
4879e90e91
commit
5c85b2b786
@ -53,7 +53,7 @@ class Dropdown extends React.Component<DropdownProps, DropdownState> {
|
||||
};
|
||||
this.wrapperRef = React.createRef();
|
||||
this.menuRef = React.createRef();
|
||||
this.curUuid == uuidv4();
|
||||
this.curUuid = uuidv4();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@ -100,6 +100,9 @@ class Dropdown extends React.Component<DropdownProps, DropdownState> {
|
||||
|
||||
@boundMethod
|
||||
handleClick() {
|
||||
if (!this.state.isOpen || !this.state.isTouched) {
|
||||
this.registerKeybindings();
|
||||
}
|
||||
this.toggleDropdown();
|
||||
}
|
||||
|
||||
@ -109,6 +112,7 @@ class Dropdown extends React.Component<DropdownProps, DropdownState> {
|
||||
this.registerKeybindings();
|
||||
}
|
||||
|
||||
@boundMethod
|
||||
registerKeybindings() {
|
||||
let keybindManager = GlobalModel.keybindManager;
|
||||
let domain = "dropdown-" + this.curUuid;
|
||||
@ -122,6 +126,7 @@ class Dropdown extends React.Component<DropdownProps, DropdownState> {
|
||||
});
|
||||
keybindManager.registerKeybinding("control", domain, "generic:cancel", (waveEvent) => {
|
||||
this.setState({ isOpen: false });
|
||||
this.unregisterKeybindings();
|
||||
return true;
|
||||
});
|
||||
keybindManager.registerKeybinding("control", domain, "generic:selectAbove", (waveEvent) => {
|
||||
@ -165,10 +170,12 @@ class Dropdown extends React.Component<DropdownProps, DropdownState> {
|
||||
}
|
||||
}
|
||||
|
||||
@boundMethod
|
||||
handleBlur() {
|
||||
this.unregisterKeybindings();
|
||||
}
|
||||
|
||||
@boundMethod
|
||||
unregisterKeybindings() {
|
||||
let domain = "dropdown-" + this.curUuid;
|
||||
GlobalModel.keybindManager.unregisterDomain(domain);
|
||||
@ -189,6 +196,7 @@ class Dropdown extends React.Component<DropdownProps, DropdownState> {
|
||||
}
|
||||
onChange(value);
|
||||
this.setState({ isOpen: false, isTouched: true });
|
||||
this.unregisterKeybindings();
|
||||
}
|
||||
|
||||
@boundMethod
|
||||
|
@ -41,9 +41,11 @@ function scrollDiv(div: any, amt: number) {
|
||||
|
||||
class HistoryKeybindings extends React.Component<{ inputObject: TextAreaInput }, {}> {
|
||||
componentDidMount(): void {
|
||||
if (GlobalModel.activeMainView != "session") {
|
||||
return;
|
||||
}
|
||||
let inputModel = GlobalModel.inputModel;
|
||||
let keybindManager = GlobalModel.keybindManager;
|
||||
|
||||
keybindManager.registerKeybinding("pane", "history", "generic:cancel", (waveEvent) => {
|
||||
inputModel.resetHistory();
|
||||
return true;
|
||||
@ -103,6 +105,9 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput }
|
||||
lastTab: boolean;
|
||||
|
||||
componentDidMount() {
|
||||
if (GlobalModel.activeMainView != "session") {
|
||||
return;
|
||||
}
|
||||
let inputObject = this.props.inputObject;
|
||||
this.lastTab = false;
|
||||
let keybindManager = GlobalModel.keybindManager;
|
||||
@ -209,6 +214,12 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput }
|
||||
inputObject.modEnter();
|
||||
return true;
|
||||
});
|
||||
keybindManager.registerDomainCallback("cmdinput", (waveEvent) => {
|
||||
if (!keybindManager.checkKeyPressed(waveEvent, "cmdinput:autocomplete")) {
|
||||
this.lastTab = false;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
@ -232,10 +232,26 @@ class KeybindManager {
|
||||
});
|
||||
}
|
||||
|
||||
runDomainCallbacks(event: WaveKeyboardEvent, curDomainCallbacks: Map<string, KeybindCallback>) {
|
||||
for (let key of curDomainCallbacks.keys()) {
|
||||
let callback = curDomainCallbacks.get(key);
|
||||
if (callback != null) {
|
||||
callback(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processLevel(nativeEvent: any, event: WaveKeyboardEvent, keybindsArray: Array<Keybind>): boolean {
|
||||
// iterate through keybinds in backwards order
|
||||
let domainCallbacksToRun: Map<string, KeybindCallback> = new Map();
|
||||
for (let index = keybindsArray.length - 1; index >= 0; index--) {
|
||||
let curKeybind = keybindsArray[index];
|
||||
if (this.domainCallbacks.has(curKeybind.domain)) {
|
||||
let curDomainCallback = this.domainCallbacks.get(curKeybind.domain);
|
||||
if (curDomainCallback != null) {
|
||||
domainCallbacksToRun.set(curKeybind.domain, curDomainCallback);
|
||||
}
|
||||
}
|
||||
if (this.checkKeyPressed(event, curKeybind.keybinding)) {
|
||||
if (DumpLogs) {
|
||||
console.log("keybind found", curKeybind);
|
||||
@ -246,23 +262,18 @@ class KeybindManager {
|
||||
shouldReturn = curKeybind.callback(event);
|
||||
shouldRunCommand = false;
|
||||
}
|
||||
if (!shouldReturn && this.domainCallbacks.has(curKeybind.domain)) {
|
||||
shouldRunCommand = false;
|
||||
let curDomainCallback = this.domainCallbacks.get(curKeybind.domain);
|
||||
if (curDomainCallback != null) {
|
||||
shouldReturn = curDomainCallback(event);
|
||||
}
|
||||
}
|
||||
if (shouldRunCommand) {
|
||||
shouldReturn = this.runSlashCommand(curKeybind);
|
||||
}
|
||||
if (shouldReturn) {
|
||||
nativeEvent.preventDefault();
|
||||
nativeEvent.stopPropagation();
|
||||
this.runDomainCallbacks(event, domainCallbacksToRun);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.runDomainCallbacks(event, domainCallbacksToRun);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -502,7 +513,7 @@ class KeybindManager {
|
||||
return foundKeybind;
|
||||
}
|
||||
|
||||
getKeyPressEventForDomain(domain: string, callback: KeybindCallback) {
|
||||
registerDomainCallback(domain: string, callback: KeybindCallback) {
|
||||
if (callback == null) {
|
||||
console.log("domain callback can't be null");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user