diff --git a/src/vs/editor/browser/standalone/simpleServices.ts b/src/vs/editor/browser/standalone/simpleServices.ts index 7c45fb30990..1292c35cba2 100644 --- a/src/vs/editor/browser/standalone/simpleServices.ts +++ b/src/vs/editor/browser/standalone/simpleServices.ts @@ -216,9 +216,10 @@ export class StandaloneKeybindingService extends KeybindingService { private _dynamicCommands: ICommandsMap; constructor(domNode: HTMLElement) { + super(domNode); + this._dynamicKeybindings = []; this._dynamicCommands = Object.create(null); - super(domNode); } public addDynamicKeybinding(keybinding: number, handler:ICommandHandler, context:string, commandId:string = null): string { diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index 9817321f769..6d8248eedfa 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -47,8 +47,6 @@ export class CodeEditorWidget extends CommonCodeEditor implements editorBrowser. @IKeybindingService keybindingService: IKeybindingService, @ITelemetryService telemetryService: ITelemetryService ) { - this.domElement = domElement; - super(domElement, options, instantiationService, codeEditorService, keybindingService, telemetryService); // track focus of the domElement and all its anchestors diff --git a/src/vs/editor/common/core/selection.ts b/src/vs/editor/common/core/selection.ts index 9c18ab95668..4412906f08b 100644 --- a/src/vs/editor/common/core/selection.ts +++ b/src/vs/editor/common/core/selection.ts @@ -14,11 +14,11 @@ export class Selection extends Range implements IEditorSelection { public positionColumn: number; constructor(selectionStartLineNumber: number, selectionStartColumn: number, positionLineNumber: number, positionColumn: number) { + super(selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn); this.selectionStartLineNumber = selectionStartLineNumber; this.selectionStartColumn = selectionStartColumn; this.positionLineNumber = positionLineNumber; this.positionColumn = positionColumn; - super(selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn); } public clone(): IEditorSelection { diff --git a/src/vs/editor/common/diff/diffComputer.ts b/src/vs/editor/common/diff/diffComputer.ts index c84a2c4b02d..0d13f6e1425 100644 --- a/src/vs/editor/common/diff/diffComputer.ts +++ b/src/vs/editor/common/diff/diffComputer.ts @@ -95,8 +95,8 @@ class LineMarkerSequence extends MarkerSequence { endColumn = lines[i].length + 1; if (shouldIgnoreTrimWhitespace) { - startColumn = this._getFirstNonBlankColumn(lines[i], 1); - endColumn = this._getLastNonBlankColumn(lines[i], 1); + startColumn = LineMarkerSequence._getFirstNonBlankColumn(lines[i], 1); + endColumn = LineMarkerSequence._getLastNonBlankColumn(lines[i], 1); } startMarkers.push({ @@ -117,7 +117,7 @@ class LineMarkerSequence extends MarkerSequence { super(buffer, startMarkers, endMarkers); } - private _getFirstNonBlankColumn(txt:string, defaultValue:number): number { + private static _getFirstNonBlankColumn(txt:string, defaultValue:number): number { var r = strings.firstNonWhitespaceIndex(txt); if (r === -1) { return defaultValue; @@ -125,7 +125,7 @@ class LineMarkerSequence extends MarkerSequence { return r + 1; } - private _getLastNonBlankColumn(txt:string, defaultValue:number): number { + private static _getLastNonBlankColumn(txt:string, defaultValue:number): number { var r = strings.lastNonWhitespaceIndex(txt); if (r === -1) { return defaultValue; diff --git a/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts b/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts index a529121ffbd..90dae20ddc9 100644 --- a/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts +++ b/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts @@ -143,17 +143,16 @@ export class GoToTypeDeclarationActions extends GoToTypeAction { } } -export class GoToDeclarationAction extends GoToTypeAction { - - public static ID = 'editor.action.goToDeclaration'; +export abstract class BaseGoToDeclarationAction extends GoToTypeAction { constructor( descriptor: editorCommon.IEditorActionDescriptorData, editor: editorCommon.ICommonCodeEditor, - @IMessageService messageService: IMessageService, - @IEditorService editorService: IEditorService + messageService: IMessageService, + editorService: IEditorService, + condition: Behaviour ) { - super(descriptor, editor, messageService, editorService, this.behaviour); + super(descriptor, editor, messageService, editorService, condition); } public getGroupId(): string { @@ -179,16 +178,27 @@ export class GoToDeclarationAction extends GoToTypeAction { }); } - protected get behaviour(): Behaviour { - return DEFAULT_BEHAVIOR; - } protected _resolve(resource: URI, position: editorCommon.IPosition): TPromise { return getDeclarationsAtPosition(this.editor.getModel(), this.editor.getPosition()); } } -export class OpenDeclarationToTheSideAction extends GoToDeclarationAction { +export class GoToDeclarationAction extends BaseGoToDeclarationAction { + + public static ID = 'editor.action.goToDeclaration'; + + constructor( + descriptor: editorCommon.IEditorActionDescriptorData, + editor: editorCommon.ICommonCodeEditor, + @IMessageService messageService: IMessageService, + @IEditorService editorService: IEditorService + ) { + super(descriptor, editor, messageService, editorService, DEFAULT_BEHAVIOR); + } +} + +export class OpenDeclarationToTheSideAction extends BaseGoToDeclarationAction { public static ID = 'editor.action.openDeclarationToTheSide'; @@ -198,11 +208,7 @@ export class OpenDeclarationToTheSideAction extends GoToDeclarationAction { @IMessageService messageService: IMessageService, @IEditorService editorService: IEditorService ) { - super(descriptor, editor, messageService, editorService); - } - - protected get behaviour(): Behaviour { - return Behaviour.WidgetFocus | Behaviour.UpdateOnCursorPositionChange; + super(descriptor, editor, messageService, editorService, Behaviour.WidgetFocus | Behaviour.UpdateOnCursorPositionChange); } protected get openToTheSide(): boolean { @@ -210,7 +216,7 @@ export class OpenDeclarationToTheSideAction extends GoToDeclarationAction { } } -export class PreviewDeclarationAction extends GoToDeclarationAction { +export class PreviewDeclarationAction extends BaseGoToDeclarationAction { public static ID = 'editor.action.previewDeclaration'; @@ -220,7 +226,7 @@ export class PreviewDeclarationAction extends GoToDeclarationAction { @IMessageService messageService: IMessageService, @IEditorService editorService: IEditorService ) { - super(descriptor, editor, messageService, editorService); + super(descriptor, editor, messageService, editorService, DEFAULT_BEHAVIOR); } protected _showSingleReferenceInPeek() { diff --git a/src/vs/editor/test/common/testModes.ts b/src/vs/editor/test/common/testModes.ts index 0852aa9471c..25b5cd39230 100644 --- a/src/vs/editor/test/common/testModes.ts +++ b/src/vs/editor/test/common/testModes.ts @@ -277,8 +277,8 @@ export class NMode extends TestingMode { public tokenizationSupport: modes.ITokenizationSupport; constructor(n:number) { - this.n = n; super(); + this.n = n; this.tokenizationSupport = new TokenizationSupport(this, { getInitialState: () => new NState(this, this.n) }, false, false); diff --git a/src/vs/platform/keybinding/browser/keybindingServiceImpl.ts b/src/vs/platform/keybinding/browser/keybindingServiceImpl.ts index 0a5b0f1b15a..02ab0d91ee8 100644 --- a/src/vs/platform/keybinding/browser/keybindingServiceImpl.ts +++ b/src/vs/platform/keybinding/browser/keybindingServiceImpl.ts @@ -138,7 +138,8 @@ export class KeybindingService extends AbstractKeybindingService implements IKey protected _domNode: HTMLElement; private _toDispose: IDisposable; - private _resolver: KeybindingResolver; + private _cachedResolver: KeybindingResolver; + private _firstTimeComputingResolver: boolean; private _currentChord: number; private _currentChordStatusMessage: IDisposable; @@ -148,14 +149,23 @@ export class KeybindingService extends AbstractKeybindingService implements IKey this._domNode = domNode; this._contexts = Object.create(null); this._contexts[String(this._myContextId)] = new KeybindingContext(this._myContextId, null); + this._cachedResolver = null; + this._firstTimeComputingResolver = true; + this._currentChord = 0; + this._currentChordStatusMessage = null; + this._toDispose = dom.addDisposableListener(this._domNode, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => { let keyEvent = new StandardKeyboardEvent(e); this._dispatch(keyEvent); }); + } - this._createOrUpdateResolver(true); - this._currentChord = 0; - this._currentChordStatusMessage = null; + private _getResolver(): KeybindingResolver { + if (!this._cachedResolver) { + this._cachedResolver = new KeybindingResolver(KeybindingsRegistry.getDefaultKeybindings(), this._getExtraKeybindings(this._firstTimeComputingResolver)); + this._firstTimeComputingResolver = false; + } + return this._cachedResolver; } public dispose(): void { @@ -176,11 +186,7 @@ export class KeybindingService extends AbstractKeybindingService implements IKey } protected updateResolver(): void { - this._createOrUpdateResolver(false); - } - - private _createOrUpdateResolver(isFirstTime: boolean): void { - this._resolver = new KeybindingResolver(KeybindingsRegistry.getDefaultKeybindings(), this._getExtraKeybindings(isFirstTime)); + this._cachedResolver = null; } protected _getExtraKeybindings(isFirstTime: boolean): IKeybindingItem[] { @@ -188,7 +194,7 @@ export class KeybindingService extends AbstractKeybindingService implements IKey } public getDefaultKeybindings(): string { - return this._resolver.getDefaultKeybindings() + '\n\n' + this._getAllCommandsAsComment(); + return this._getResolver().getDefaultKeybindings() + '\n\n' + this._getAllCommandsAsComment(); } public customKeybindingsCount(): number { @@ -196,11 +202,11 @@ export class KeybindingService extends AbstractKeybindingService implements IKey } public lookupKeybindings(commandId: string): Keybinding[] { - return this._resolver.lookupKeybinding(commandId); + return this._getResolver().lookupKeybinding(commandId); } private _getAllCommandsAsComment(): string { - let boundCommands = this._resolver.getDefaultBoundCommands(); + let boundCommands = this._getResolver().getDefaultBoundCommands(); let unboundCommands = Object.keys(KeybindingsRegistry.getCommands()).filter(commandId => commandId[0] !== '_' && !boundCommands[commandId]); unboundCommands.sort(); let pretty = unboundCommands.join('\n// - '); @@ -223,7 +229,7 @@ export class KeybindingService extends AbstractKeybindingService implements IKey let contextValue = context.getValue(); // console.log(JSON.stringify(contextValue, null, '\t')); - let resolveResult = this._resolver.resolve(contextValue, this._currentChord, e.asKeybinding()); + let resolveResult = this._getResolver().resolve(contextValue, this._currentChord, e.asKeybinding()); if (resolveResult && resolveResult.enterChord) { e.preventDefault(); diff --git a/src/vs/workbench/api/node/extHostTypes.ts b/src/vs/workbench/api/node/extHostTypes.ts index 0905bb768d4..0a0f3abb9be 100644 --- a/src/vs/workbench/api/node/extHostTypes.ts +++ b/src/vs/workbench/api/node/extHostTypes.ts @@ -290,10 +290,10 @@ export class Selection extends Range { throw new Error('Invalid arguments'); } + super(anchor, active); + this._anchor = anchor; this._active = active; - - super(anchor, active); } get isReversed(): boolean {