From 29976b03c1f9a7d41d0900e4e415fb49e0f51ca1 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 10 Mar 2016 17:46:23 +0100 Subject: [PATCH] Add cursorStyle to TextEditorOptions --- src/vs/vscode.d.ts | 21 +++++++ src/vs/workbench/api/node/extHost.api.impl.ts | 2 + src/vs/workbench/api/node/extHostTypes.ts | 6 +- .../workbench/api/node/mainThreadEditors.ts | 62 +++++++++++++++++-- 4 files changed, 84 insertions(+), 7 deletions(-) diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 0fda7355b5c..68a6d7bef50 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -520,6 +520,20 @@ declare namespace vscode { viewColumn: ViewColumn; } + /** + * Rendering style of the cursor. + */ + export enum TextEditorCursorStyle { + /** + * Render the cursor as a vertical line. + */ + Line = 1, + /** + * Render the cursor as a block. + */ + Block = 2 + } + /** * Represents a [text editor](#TextEditor)'s [options](#TextEditor.options). */ @@ -540,6 +554,13 @@ declare namespace vscode { * When setting a text editor's options, this property is optional and it can be a boolean or `"auto"`. */ insertSpaces?: boolean | string; + + /** + * The rendering style of the cursor in this editor. + * When getting a text editor's options, this property will always be present. + * When setting a text editor's options, this property is optional. + */ + cursorStyle?: TextEditorCursorStyle; } /** diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 86d3064bd03..dd7a094f04f 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -86,6 +86,7 @@ export class ExtHostAPIImplementation { OverviewRulerLane: typeof vscode.OverviewRulerLane; TextEditorRevealType: typeof vscode.TextEditorRevealType; EndOfLine: typeof vscode.EndOfLine; + TextEditorCursorStyle: typeof vscode.TextEditorCursorStyle; commands: typeof vscode.commands; window: typeof vscode.window; workspace: typeof vscode.workspace; @@ -132,6 +133,7 @@ export class ExtHostAPIImplementation { this.OverviewRulerLane = EditorCommon.OverviewRulerLane; this.TextEditorRevealType = TextEditorRevealType; this.EndOfLine = extHostTypes.EndOfLine; + this.TextEditorCursorStyle = extHostTypes.TextEditorCursorStyle; errors.setUnexpectedErrorHandler((err) => { this._proxy.onUnexpectedExtHostError(errors.transformErrorForSerialization(err)); diff --git a/src/vs/workbench/api/node/extHostTypes.ts b/src/vs/workbench/api/node/extHostTypes.ts index 7bba90c4858..a80a966428d 100644 --- a/src/vs/workbench/api/node/extHostTypes.ts +++ b/src/vs/workbench/api/node/extHostTypes.ts @@ -692,4 +692,8 @@ export enum StatusBarAlignment { export enum EndOfLine { LF = 1, CRLF = 2 -} \ No newline at end of file +} +export enum TextEditorCursorStyle { + Line = 1, + Block = 2 +} diff --git a/src/vs/workbench/api/node/mainThreadEditors.ts b/src/vs/workbench/api/node/mainThreadEditors.ts index d0eb0a02b49..23fcb01f84a 100644 --- a/src/vs/workbench/api/node/mainThreadEditors.ts +++ b/src/vs/workbench/api/node/mainThreadEditors.ts @@ -13,15 +13,17 @@ import {IDisposable, disposeAll} from 'vs/base/common/lifecycle'; import {RunOnceScheduler} from 'vs/base/common/async'; import {Range} from 'vs/editor/common/core/range'; import {Selection} from 'vs/editor/common/core/selection'; -import {EndOfLine} from 'vs/workbench/api/node/extHostTypes'; +import {EndOfLine, TextEditorCursorStyle} from 'vs/workbench/api/node/extHostTypes'; export interface ITextEditorConfigurationUpdate { tabSize?: number | string; insertSpaces?: boolean | string; + cursorStyle?: TextEditorCursorStyle; } export interface IResolvedTextEditorConfiguration { tabSize: number; insertSpaces: boolean; + cursorStyle: TextEditorCursorStyle; } function configurationsEqual(a:IResolvedTextEditorConfiguration, b:IResolvedTextEditorConfiguration) { @@ -86,10 +88,10 @@ export class MainThreadTextEditor { this._onConfigurationChanged = new Emitter(); this._lastSelection = [ new Selection(1,1,1,1) ]; - this._setConfiguration(MainThreadTextEditor._readConfiguration(this._model)); + this._setConfiguration(this._readConfiguration(this._model, this._codeEditor)); this._modelListeners = []; this._modelListeners.push(this._model.addListener2(EditorCommon.EventType.ModelOptionsChanged, (e) => { - this._setConfiguration(MainThreadTextEditor._readConfiguration(this._model)); + this._setConfiguration(this._readConfiguration(this._model, this._codeEditor)); })); this.setCodeEditor(codeEditor); @@ -138,6 +140,10 @@ export class MainThreadTextEditor { this._codeEditorListeners.push(this._codeEditor.addListener2(EditorCommon.EventType.EditorBlur, () => { this._focusTracker.onLostFocus(); })); + this._codeEditorListeners.push(this._codeEditor.addListener2(EditorCommon.EventType.ConfigurationChanged, () => { + this._setConfiguration(this._readConfiguration(this._model, this._codeEditor)); + })); + this._setConfiguration(this._readConfiguration(this._model, this._codeEditor)); } } @@ -173,7 +179,7 @@ export class MainThreadTextEditor { return this._configuration; } - public setConfiguration(newConfiguration:ITextEditorConfigurationUpdate): void { + private _setIndentConfiguration(newConfiguration:ITextEditorConfigurationUpdate): void { if (newConfiguration.tabSize === 'auto' || newConfiguration.insertSpaces === 'auto') { // one of the options was set to 'auto' => detect indentation @@ -212,6 +218,23 @@ export class MainThreadTextEditor { this._model.updateOptions(newOpts); } + public setConfiguration(newConfiguration:ITextEditorConfigurationUpdate): void { + this._setIndentConfiguration(newConfiguration); + + if (newConfiguration.cursorStyle) { + let newCursorStyle = cursorStyleToString(newConfiguration.cursorStyle); + + if (!this._codeEditor) { + console.warn('setConfiguration on invisible editor'); + return; + } + + this._codeEditor.updateOptions({ + cursorStyle: newCursorStyle + }); + } + } + public setDecorations(key: string, ranges:EditorCommon.IRangeWithMessage[]): void { if (!this._codeEditor) { console.warn('setDecorations on invisible editor'); @@ -236,11 +259,18 @@ export class MainThreadTextEditor { } } - private static _readConfiguration(model:EditorCommon.IModel): IResolvedTextEditorConfiguration { + private _readConfiguration(model:EditorCommon.IModel, codeEditor:EditorCommon.ICommonCodeEditor): IResolvedTextEditorConfiguration { + let cursorStyle = this._configuration ? this._configuration.cursorStyle : TextEditorCursorStyle.Line; + if (codeEditor) { + let codeEditorOpts = codeEditor.getConfiguration(); + cursorStyle = cursorStyleFromString(codeEditorOpts.cursorStyle); + } + let indent = model.getOptions(); return { insertSpaces: indent.insertSpaces, - tabSize: indent.tabSize + tabSize: indent.tabSize, + cursorStyle: cursorStyle }; } @@ -615,4 +645,24 @@ function strcmp(a:string, b:string): number { return 1; } return 0; +} + +function cursorStyleToString(cursorStyle:TextEditorCursorStyle): string { + if (cursorStyle === TextEditorCursorStyle.Line) { + return 'line'; + } else if (cursorStyle === TextEditorCursorStyle.Block) { + return 'block'; + } else { + throw new Error('cursorStyleToString: Unknown cursorStyle'); + } +} + +function cursorStyleFromString(cursorStyle:string): TextEditorCursorStyle { + if (cursorStyle === 'line') { + return TextEditorCursorStyle.Line; + } else if (cursorStyle === 'block') { + return TextEditorCursorStyle.Block; + } else { + throw new Error('cursorStyleFromString: Unknown cursorStyle'); + } } \ No newline at end of file -- GitLab