提交 f10f31e7 编写于 作者: S Sandeep Somavarapu

Fix #23039

- Default value in keybindings.json should be an empty array
- Handle and show errors while editing in the editor
上级 d6bf8879
......@@ -30,7 +30,7 @@ import { List } from 'vs/base/browser/ui/list/listWidget';
import { IDelegate, IRenderer, IListContextMenuEvent, IListEvent } from 'vs/base/browser/ui/list/list';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IChoiceService, Severity } from 'vs/platform/message/common/message';
import { IChoiceService, IMessageService, Severity } from 'vs/platform/message/common/message';
let $ = DOM.$;
......@@ -90,6 +90,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
@IListService private listService: IListService,
@IContextKeyService private contextKeyService: IContextKeyService,
@IChoiceService private choiceService: IChoiceService,
@IMessageService private messageService: IMessageService,
@IClipboardService private clipboardService: IClipboardService,
@IInstantiationService private instantiationService: IInstantiationService
) {
......@@ -172,8 +173,13 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
}
return null;
}).then(() => {
this.overlayContainer.style.display = 'none';
this.hideOverlayContainer();
this.focusEntry(keybindingEntry, false);
}, error => {
this.hideOverlayContainer();
this.onKeybindingEditingError(error);
this.focusEntry(keybindingEntry, false);
return error;
});
}
......@@ -187,7 +193,11 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
}
return null;
})
.then(() => this.focus());
.then(() => this.focus(),
error => {
this.onKeybindingEditingError(error);
this.focusEntry(keybindingEntry, false);
});
}
return TPromise.as(null);
}
......@@ -202,7 +212,11 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
}
return null;
})
.then(() => this.focus());
.then(() => this.focus(),
error => {
this.onKeybindingEditingError(error);
this.focusEntry(keybindingEntry, false);
});
}
return TPromise.as(null);
}
......@@ -226,9 +240,13 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
private createOverlayContainer(parent: HTMLElement): void {
this.overlayContainer = DOM.append(parent, $('.overlay-container'));
this.overlayContainer.style.position = 'absolute';
this.overlayContainer.style.display = 'none';
this.overlayContainer.style.zIndex = '10';
this.defineKeybindingWidget = this._register(this.instantiationService.createInstance(DefineKeybindingWidget, this.overlayContainer));
this.hideOverlayContainer();
}
private hideOverlayContainer() {
this.overlayContainer.style.display = 'none';
}
private createHeader(parent: HTMLElement): void {
......@@ -366,6 +384,10 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
run: () => this.copyKeybinding(keybindingItem)
};
}
private onKeybindingEditingError(error: any): void {
this.messageService.show(Severity.Error, localize('error', "Error '{0}' while editing keybinding. Please open 'keybindings.json' file and check.", `${error}`));
}
}
class Delegate implements IDelegate<IListEntry> {
......
......@@ -6,6 +6,7 @@
import { localize } from 'vs/nls';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { isArray } from 'vs/base/common/types';
import { Queue } from 'vs/base/common/async';
import { IReference, Disposable } from 'vs/base/common/lifecycle';
import * as json from 'vs/base/common/json';
......@@ -213,7 +214,7 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding
private resolveModelReference(): TPromise<IReference<ITextEditorModel>> {
return this.fileService.existsFile(this.resource)
.then(exists => {
const result = exists ? TPromise.as(null) : this.fileService.updateContent(this.resource, '{}', { encoding: 'utf8' });
const result = exists ? TPromise.as(null) : this.fileService.updateContent(this.resource, '[]', { encoding: 'utf8' });
return result.then(() => this.textModelResolverService.createModelReference(this.resource));
});
}
......@@ -237,7 +238,7 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding
private hasParseErrors(model: editorCommon.IModel): boolean {
const parseErrors: json.ParseError[] = [];
json.parse(model.getValue(), parseErrors, { allowTrailingComma: true });
return parseErrors.length > 0;
const result = json.parse(model.getValue(), parseErrors, { allowTrailingComma: true });
return parseErrors.length > 0 || !isArray(result);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册