提交 29976b03 编写于 作者: A Alex Dima

Add cursorStyle to TextEditorOptions

上级 1fb7eb9c
......@@ -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;
}
/**
......
......@@ -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));
......
......@@ -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
}
......@@ -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<IResolvedTextEditorConfiguration>();
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册