Skip to content

Commit

Permalink
Merge pull request #1586 from markrendle/cursor-style
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Jan 11, 2016
2 parents db1768a + 91af12c commit 82f2a8a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/vs/editor/browser/viewParts/viewCursors/viewCursors.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@

.monaco-editor .cursors-layer > .cursor {
position: absolute;
width: 2px;
cursor: text;
}

.monaco-editor .cursors-layer > .cursor.secondary {
width: 1px;
opacity: 0.6;
}
}

/* -- line-style -- */
.monaco-editor .cursors-layer.cursor-line-style > .cursor {
width: 2px;
}
.monaco-editor .cursors-layer.cursor-line-style > .cursor.secondary {
width: 1px;
}

/* -- block-style -- */
.monaco-editor .cursors-layer.cursor-block-style > .cursor {
width: 1ch;
}
25 changes: 24 additions & 1 deletion src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class ViewCursors extends ViewPart {
this._secondaryCursors = [];

this._domNode = document.createElement('div');
this._domNode.className = EditorBrowser.ClassNames.VIEW_CURSORS_LAYER;
this._updateDomClassName();
if (Browser.canUseTranslate3d) {
this._domNode.style.transform = 'translate3d(0px, 0px, 0px)';
}
Expand Down Expand Up @@ -137,6 +137,9 @@ export class ViewCursors extends ViewPart {
public onConfigurationChanged(e:EditorCommon.IConfigurationChangedEvent): boolean {
this._primaryCursor.onConfigurationChanged(e);
this._updateBlinking();
if (e.cursorStyle) {
this._updateDomClassName();
}
for (var i = 0, len = this._secondaryCursors.length; i < len; i++) {
this._secondaryCursors[i].onConfigurationChanged(e);
}
Expand Down Expand Up @@ -209,6 +212,26 @@ export class ViewCursors extends ViewPart {
}
// --- end blinking logic

private _updateDomClassName(): void {
this._domNode.className = this._getClassName();
}

private _getClassName(): string {
let result = EditorBrowser.ClassNames.VIEW_CURSORS_LAYER;
let extraClassName: string;
switch (this._context.configuration.editor.cursorStyle) {
case 'line':
extraClassName = 'cursor-line-style';
break;
case 'block':
extraClassName = 'cursor-block-style';
break;
default:
extraClassName = 'cursor-line-style';
}
return result + ' ' + extraClassName;
}

private _blink(): void {
if (this._isVisible) {
this._hide();
Expand Down
8 changes: 8 additions & 0 deletions src/vs/editor/common/config/commonEditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class InternalEditorOptionsHelper {
scrollbar: scrollbar,
overviewRulerLanes: toInteger(opts.overviewRulerLanes, 0, 3),
cursorBlinking: opts.cursorBlinking,
cursorStyle: opts.cursorStyle,
hideCursorInOverviewRuler: toBoolean(opts.hideCursorInOverviewRuler),
scrollBeyondLastLine: toBoolean(opts.scrollBeyondLastLine),
wrappingIndent: opts.wrappingIndent,
Expand Down Expand Up @@ -238,6 +239,7 @@ class InternalEditorOptionsHelper {
scrollbar: (!this._scrollbarOptsEqual(prevOpts.scrollbar, newOpts.scrollbar)),
overviewRulerLanes: (prevOpts.overviewRulerLanes !== newOpts.overviewRulerLanes),
cursorBlinking: (prevOpts.cursorBlinking !== newOpts.cursorBlinking),
cursorStyle: (prevOpts.cursorStyle !== newOpts.cursorStyle),
hideCursorInOverviewRuler: (prevOpts.hideCursorInOverviewRuler !== newOpts.hideCursorInOverviewRuler),
scrollBeyondLastLine: (prevOpts.scrollBeyondLastLine !== newOpts.scrollBeyondLastLine),
wrappingIndent: (prevOpts.wrappingIndent !== newOpts.wrappingIndent),
Expand Down Expand Up @@ -802,6 +804,12 @@ configurationRegistry.registerConfiguration({
'default': DefaultConfig.editor.cursorBlinking,
'description': nls.localize('cursorBlinking', "Controls the cursor blinking animation, accepted values are 'blink', 'visible', and 'hidden'")
},
'editor.cursorStyle' : {
'type': 'string',
'enum': ['block', 'line'],
'default': DefaultConfig.editor.cursorStyle,
'description': nls.localize('cursorStyle', "Controls the cursor style, accepted values are 'block' and 'line'")
},
'editor.hideCursorInOverviewRuler' : {
'type': 'boolean',
'default': DefaultConfig.editor.hideCursorInOverviewRuler,
Expand Down
1 change: 1 addition & 0 deletions src/vs/editor/common/config/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ConfigClass implements IConfiguration {
},
overviewRulerLanes: 2,
cursorBlinking: 'blink',
cursorStyle: 'line',
hideCursorInOverviewRuler: false,
scrollBeyondLastLine: true,
automaticLayout: false,
Expand Down
7 changes: 7 additions & 0 deletions src/vs/editor/common/editorCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ export interface ICommonEditorOptions {
* Defaults to 'blink'.
*/
cursorBlinking?:string;
/**
* Control the cursor style, either 'block' or 'line'.
* Defaults to 'line'.
*/
cursorStyle?:string;
/**
* Should the cursor be hidden in the overview ruler.
* Defaults to false.
Expand Down Expand Up @@ -585,6 +590,7 @@ export interface IInternalEditorOptions {
scrollbar:IInternalEditorScrollbarOptions;
overviewRulerLanes:number;
cursorBlinking:string;
cursorStyle:string;
hideCursorInOverviewRuler:boolean;
scrollBeyondLastLine:boolean;
wrappingIndent: string;
Expand Down Expand Up @@ -676,6 +682,7 @@ export interface IConfigurationChangedEvent {
scrollbar:boolean;
overviewRulerLanes:boolean;
cursorBlinking:boolean;
cursorStyle:boolean;
hideCursorInOverviewRuler:boolean;
scrollBeyondLastLine:boolean;
wrappingIndent:boolean;
Expand Down

0 comments on commit 82f2a8a

Please sign in to comment.