Skip to content

Commit 7c5b8cc

Browse files
authored
Merge pull request microsoft#183303 from microsoft/ulugbekna/statistical-camel
define-keybinding widget: escape clears if non-empty, otherwise hides the widget
2 parents 21ec251 + 8e705be commit 7c5b8cc

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

src/vs/workbench/contrib/preferences/browser/keybindingWidgets.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ export class KeybindingsSearchWidget extends SearchWidget {
5959
@IKeybindingService keybindingService: IKeybindingService,
6060
) {
6161
super(parent, options, contextViewService, instantiationService, contextKeyService, keybindingService);
62+
6263
this._register(toDisposable(() => this.stopRecordingKeys()));
64+
6365
this._chords = null;
6466
this._inputValue = '';
65-
66-
this._reset();
6767
}
6868

6969
override clear(): void {
70-
this._reset();
70+
this._chords = null;
7171
super.clear();
7272
}
7373

@@ -81,7 +81,7 @@ export class KeybindingsSearchWidget extends SearchWidget {
8181
}
8282

8383
stopRecordingKeys(): void {
84-
this._reset();
84+
this._chords = null;
8585
this.recordDisposables.clear();
8686
}
8787

@@ -90,10 +90,6 @@ export class KeybindingsSearchWidget extends SearchWidget {
9090
this.inputBox.value = this._inputValue;
9191
}
9292

93-
private _reset() {
94-
this._chords = null;
95-
}
96-
9793
private _onKeyDown(keyboardEvent: IKeyboardEvent): void {
9894
keyboardEvent.preventDefault();
9995
keyboardEvent.stopPropagation();
@@ -103,10 +99,6 @@ export class KeybindingsSearchWidget extends SearchWidget {
10399
return;
104100
}
105101
if (keyboardEvent.equals(KeyCode.Escape)) {
106-
if (this._chords !== null) {
107-
this.clear();
108-
}
109-
110102
this._onEscape.fire();
111103
return;
112104
}
@@ -185,8 +177,8 @@ export class DefineKeybindingWidget extends Widget {
185177
this._keybindingInputWidget.startRecordingKeys();
186178
this._register(this._keybindingInputWidget.onKeybinding(keybinding => this.onKeybinding(keybinding)));
187179
this._register(this._keybindingInputWidget.onEnter(() => this.hide()));
188-
this._register(this._keybindingInputWidget.onEscape(() => this.onEscape()));
189-
this._register(this._keybindingInputWidget.onBlur(() => this.onBlur()));
180+
this._register(this._keybindingInputWidget.onEscape(() => this.clearOrHide()));
181+
this._register(this._keybindingInputWidget.onBlur(() => this.onCancel()));
190182

191183
this._outputNode = dom.append(this._domNode.domNode, dom.$('.output'));
192184
this._showExistingKeybindingsNode = dom.append(this._domNode.domNode, dom.$('.existing'));
@@ -251,19 +243,15 @@ export class DefineKeybindingWidget extends Widget {
251243
dom.clearNode(this._outputNode);
252244
dom.clearNode(this._showExistingKeybindingsNode);
253245

254-
255-
256246
const firstLabel = new KeybindingLabel(this._outputNode, OS, defaultKeybindingLabelStyles);
257247
firstLabel.set(withNullAsUndefined(this._chords?.[0]));
258248

259-
260249
if (this._chords) {
261250
for (let i = 1; i < this._chords.length; i++) {
262251
this._outputNode.appendChild(document.createTextNode(nls.localize('defineKeybinding.chordsTo', "chord to")));
263252
const chordLabel = new KeybindingLabel(this._outputNode, OS, defaultKeybindingLabelStyles);
264253
chordLabel.set(this._chords[i]);
265254
}
266-
267255
}
268256

269257
const label = this.getUserSettingsLabel();
@@ -280,19 +268,20 @@ export class DefineKeybindingWidget extends Widget {
280268
return label;
281269
}
282270

283-
private onBlur(): void {
271+
private onCancel(): void {
284272
this._chords = null;
285273
this.hide();
286274
}
287275

288-
private onEscape(): void {
289-
if (this._chords !== null) {
276+
private clearOrHide(): void {
277+
if (this._chords === null) {
278+
this.hide();
279+
} else {
290280
this._chords = null;
281+
this._keybindingInputWidget.clear();
291282
dom.clearNode(this._outputNode);
292283
dom.clearNode(this._showExistingKeybindingsNode);
293-
return;
294284
}
295-
this.hide();
296285
}
297286

298287
private hide(): void {

0 commit comments

Comments
 (0)