提交 e5dfb9ee 编写于 作者: B Brandon Ruggles

Conflicts are now displayed when defining a new keybinding.

上级 3b02dc24
......@@ -25,6 +25,7 @@
"check-monaco-editor-compilation": "tsc -p src/tsconfig.monaco.json --noEmit"
},
"dependencies": {
"@types/which": "^1.0.28",
"applicationinsights": "0.18.0",
"fast-plist": "0.1.2",
"gc-signals": "^0.0.1",
......
......@@ -144,6 +144,9 @@ export class DefineKeybindingWidget extends Widget {
private _onHide = this._register(new Emitter<void>());
private _onDidChange = this._register(new Emitter<[ResolvedKeybinding, ResolvedKeybinding]>());
public onDidChange: Event<[ResolvedKeybinding, ResolvedKeybinding]> = this._onDidChange.event;
constructor(
parent: HTMLElement,
@IInstantiationService private instantiationService: IInstantiationService,
......@@ -219,7 +222,7 @@ export class DefineKeybindingWidget extends Widget {
}));
this._keybindingInputWidget = this._register(this.instantiationService.createInstance(KeybindingInputWidget, this._domNode.domNode, {}));
this._register(this._keybindingInputWidget.onKeybinding(keybinding => this.printKeybinding(keybinding)));
this._register(this._keybindingInputWidget.onKeybinding(keybinding => { this.printKeybinding(keybinding); this._onDidChange.fire(keybinding); }));
this._register(this._keybindingInputWidget.onEnter(() => this.hide()));
this._register(this._keybindingInputWidget.onEscape(() => this.onCancel()));
this._register(this._keybindingInputWidget.onBlur(() => this.onCancel()));
......@@ -239,6 +242,17 @@ export class DefineKeybindingWidget extends Widget {
}
}
public printConflicts(numConflicts: number): void {
let outputString: string = nls.localize('defineKeybinding.conflicts', "Conflict(s)");
if (numConflicts > 0) {
outputString = '(' + numConflicts + ' ' + outputString + ')';
}
else {
outputString = '';
}
this._outputNode.appendChild(document.createTextNode(outputString));
}
private onCancel(): void {
this._firstPart = null;
this._chordPart = null;
......
......@@ -267,11 +267,29 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
return TPromise.as(null);
}
showOverlayConflicts(keybinding: [ResolvedKeybinding, ResolvedKeybinding]): void {
const [firstPart, chordPart] = keybinding;
let searchLabel = firstPart.getAriaLabel();
if (chordPart !== null) {
searchLabel += ' ' + chordPart.getAriaLabel();
}
const keybindingsEntries: IKeybindingItemEntry[] = this.keybindingsEditorModel.fetch(searchLabel, this.sortByPrecedence.checked);
let conflictsList: IKeybindingItemEntry[] = [];
for (let keybindingEntry of keybindingsEntries) {
let binding = keybindingEntry.keybindingItem.keybinding;
if (binding !== null && binding.getAriaLabel() === searchLabel) {
conflictsList.push(keybindingEntry);
}
}
this.defineKeybindingWidget.printConflicts(conflictsList.length);
}
private createOverlayContainer(parent: HTMLElement): void {
this.overlayContainer = DOM.append(parent, $('.overlay-container'));
this.overlayContainer.style.position = 'absolute';
this.overlayContainer.style.zIndex = '10';
this.defineKeybindingWidget = this._register(this.instantiationService.createInstance(DefineKeybindingWidget, this.overlayContainer));
this._register(this.defineKeybindingWidget.onDidChange(keybinding => this.showOverlayConflicts(keybinding)));
this.hideOverlayContainer();
}
......
......@@ -43,6 +43,10 @@
version "1.16.34"
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-1.16.34.tgz#a9761fff33d0f7b3fe61875b577778a2576a9a03"
"@types/which@^1.0.28":
version "1.0.28"
resolved "https://registry.yarnpkg.com/@types/which/-/which-1.0.28.tgz#016e387629b8817bed653fe32eab5d11279c8df6"
abbrev@1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册