Skip to content

Commit 5c85b2b

Browse files
authored
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
1 parent 4879e90 commit 5c85b2b

3 files changed

Lines changed: 40 additions & 10 deletions

File tree

src/app/common/elements/dropdown.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Dropdown extends React.Component<DropdownProps, DropdownState> {
5353
};
5454
this.wrapperRef = React.createRef();
5555
this.menuRef = React.createRef();
56-
this.curUuid == uuidv4();
56+
this.curUuid = uuidv4();
5757
}
5858

5959
componentDidMount() {
@@ -100,6 +100,9 @@ class Dropdown extends React.Component<DropdownProps, DropdownState> {
100100

101101
@boundMethod
102102
handleClick() {
103+
if (!this.state.isOpen || !this.state.isTouched) {
104+
this.registerKeybindings();
105+
}
103106
this.toggleDropdown();
104107
}
105108

@@ -109,6 +112,7 @@ class Dropdown extends React.Component<DropdownProps, DropdownState> {
109112
this.registerKeybindings();
110113
}
111114

115+
@boundMethod
112116
registerKeybindings() {
113117
let keybindManager = GlobalModel.keybindManager;
114118
let domain = "dropdown-" + this.curUuid;
@@ -122,6 +126,7 @@ class Dropdown extends React.Component<DropdownProps, DropdownState> {
122126
});
123127
keybindManager.registerKeybinding("control", domain, "generic:cancel", (waveEvent) => {
124128
this.setState({ isOpen: false });
129+
this.unregisterKeybindings();
125130
return true;
126131
});
127132
keybindManager.registerKeybinding("control", domain, "generic:selectAbove", (waveEvent) => {
@@ -165,10 +170,12 @@ class Dropdown extends React.Component<DropdownProps, DropdownState> {
165170
}
166171
}
167172

173+
@boundMethod
168174
handleBlur() {
169175
this.unregisterKeybindings();
170176
}
171177

178+
@boundMethod
172179
unregisterKeybindings() {
173180
let domain = "dropdown-" + this.curUuid;
174181
GlobalModel.keybindManager.unregisterDomain(domain);
@@ -189,6 +196,7 @@ class Dropdown extends React.Component<DropdownProps, DropdownState> {
189196
}
190197
onChange(value);
191198
this.setState({ isOpen: false, isTouched: true });
199+
this.unregisterKeybindings();
192200
}
193201

194202
@boundMethod

src/app/workspace/cmdinput/textareainput.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ function scrollDiv(div: any, amt: number) {
4141

4242
class HistoryKeybindings extends React.Component<{ inputObject: TextAreaInput }, {}> {
4343
componentDidMount(): void {
44+
if (GlobalModel.activeMainView != "session") {
45+
return;
46+
}
4447
let inputModel = GlobalModel.inputModel;
4548
let keybindManager = GlobalModel.keybindManager;
46-
4749
keybindManager.registerKeybinding("pane", "history", "generic:cancel", (waveEvent) => {
4850
inputModel.resetHistory();
4951
return true;
@@ -103,6 +105,9 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput }
103105
lastTab: boolean;
104106

105107
componentDidMount() {
108+
if (GlobalModel.activeMainView != "session") {
109+
return;
110+
}
106111
let inputObject = this.props.inputObject;
107112
this.lastTab = false;
108113
let keybindManager = GlobalModel.keybindManager;
@@ -209,6 +214,12 @@ class CmdInputKeybindings extends React.Component<{ inputObject: TextAreaInput }
209214
inputObject.modEnter();
210215
return true;
211216
});
217+
keybindManager.registerDomainCallback("cmdinput", (waveEvent) => {
218+
if (!keybindManager.checkKeyPressed(waveEvent, "cmdinput:autocomplete")) {
219+
this.lastTab = false;
220+
}
221+
return false;
222+
});
212223
}
213224

214225
componentWillUnmount() {

src/util/keyutil.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,26 @@ class KeybindManager {
232232
});
233233
}
234234

235+
runDomainCallbacks(event: WaveKeyboardEvent, curDomainCallbacks: Map<string, KeybindCallback>) {
236+
for (let key of curDomainCallbacks.keys()) {
237+
let callback = curDomainCallbacks.get(key);
238+
if (callback != null) {
239+
callback(event);
240+
}
241+
}
242+
}
243+
235244
processLevel(nativeEvent: any, event: WaveKeyboardEvent, keybindsArray: Array<Keybind>): boolean {
236245
// iterate through keybinds in backwards order
246+
let domainCallbacksToRun: Map<string, KeybindCallback> = new Map();
237247
for (let index = keybindsArray.length - 1; index >= 0; index--) {
238248
let curKeybind = keybindsArray[index];
249+
if (this.domainCallbacks.has(curKeybind.domain)) {
250+
let curDomainCallback = this.domainCallbacks.get(curKeybind.domain);
251+
if (curDomainCallback != null) {
252+
domainCallbacksToRun.set(curKeybind.domain, curDomainCallback);
253+
}
254+
}
239255
if (this.checkKeyPressed(event, curKeybind.keybinding)) {
240256
if (DumpLogs) {
241257
console.log("keybind found", curKeybind);
@@ -246,23 +262,18 @@ class KeybindManager {
246262
shouldReturn = curKeybind.callback(event);
247263
shouldRunCommand = false;
248264
}
249-
if (!shouldReturn && this.domainCallbacks.has(curKeybind.domain)) {
250-
shouldRunCommand = false;
251-
let curDomainCallback = this.domainCallbacks.get(curKeybind.domain);
252-
if (curDomainCallback != null) {
253-
shouldReturn = curDomainCallback(event);
254-
}
255-
}
256265
if (shouldRunCommand) {
257266
shouldReturn = this.runSlashCommand(curKeybind);
258267
}
259268
if (shouldReturn) {
260269
nativeEvent.preventDefault();
261270
nativeEvent.stopPropagation();
271+
this.runDomainCallbacks(event, domainCallbacksToRun);
262272
return true;
263273
}
264274
}
265275
}
276+
this.runDomainCallbacks(event, domainCallbacksToRun);
266277
return false;
267278
}
268279

@@ -502,7 +513,7 @@ class KeybindManager {
502513
return foundKeybind;
503514
}
504515

505-
getKeyPressEventForDomain(domain: string, callback: KeybindCallback) {
516+
registerDomainCallback(domain: string, callback: KeybindCallback) {
506517
if (callback == null) {
507518
console.log("domain callback can't be null");
508519
}

0 commit comments

Comments
 (0)