diff --git a/src/app/common/elements/dropdown.tsx b/src/app/common/elements/dropdown.tsx index 1b454afce..eaa0f704b 100644 --- a/src/app/common/elements/dropdown.tsx +++ b/src/app/common/elements/dropdown.tsx @@ -53,7 +53,7 @@ class Dropdown extends React.Component { }; this.wrapperRef = React.createRef(); this.menuRef = React.createRef(); - this.curUuid == uuidv4(); + this.curUuid = uuidv4(); } componentDidMount() { @@ -100,6 +100,9 @@ class Dropdown extends React.Component { @boundMethod handleClick() { + if (!this.state.isOpen || !this.state.isTouched) { + this.registerKeybindings(); + } this.toggleDropdown(); } @@ -109,6 +112,7 @@ class Dropdown extends React.Component { this.registerKeybindings(); } + @boundMethod registerKeybindings() { let keybindManager = GlobalModel.keybindManager; let domain = "dropdown-" + this.curUuid; @@ -122,6 +126,7 @@ class Dropdown extends React.Component { }); 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 { } } + @boundMethod handleBlur() { this.unregisterKeybindings(); } + @boundMethod unregisterKeybindings() { let domain = "dropdown-" + this.curUuid; GlobalModel.keybindManager.unregisterDomain(domain); @@ -189,6 +196,7 @@ class Dropdown extends React.Component { } onChange(value); this.setState({ isOpen: false, isTouched: true }); + this.unregisterKeybindings(); } @boundMethod diff --git a/src/app/workspace/cmdinput/textareainput.tsx b/src/app/workspace/cmdinput/textareainput.tsx index e3a349230..f553780c6 100644 --- a/src/app/workspace/cmdinput/textareainput.tsx +++ b/src/app/workspace/cmdinput/textareainput.tsx @@ -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() { diff --git a/src/util/keyutil.ts b/src/util/keyutil.ts index 7447cb107..c70f67e0b 100644 --- a/src/util/keyutil.ts +++ b/src/util/keyutil.ts @@ -232,10 +232,26 @@ class KeybindManager { }); } + runDomainCallbacks(event: WaveKeyboardEvent, curDomainCallbacks: Map) { + for (let key of curDomainCallbacks.keys()) { + let callback = curDomainCallbacks.get(key); + if (callback != null) { + callback(event); + } + } + } + processLevel(nativeEvent: any, event: WaveKeyboardEvent, keybindsArray: Array): boolean { // iterate through keybinds in backwards order + let domainCallbacksToRun: Map = 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"); }