Skip to content

Commit 648281e

Browse files
omar-csalexdima
andauthored
Adds options for cursor height (microsoft#211473)
* Issue microsoft#168531: Cursor Height. Changed viewCursor to consider cursor height each time cursor is rendered. Cursor height is dependent on font line height and font size. * Reduce formatting diffs * Small fixes --------- Co-authored-by: Alexandru Dima <[email protected]>
1 parent 58ff3c9 commit 648281e

File tree

4 files changed

+291
-266
lines changed

4 files changed

+291
-266
lines changed

src/vs/editor/browser/viewParts/viewCursors/viewCursor.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class ViewCursor {
4747

4848
private _cursorStyle: TextEditorCursorStyle;
4949
private _lineCursorWidth: number;
50+
private _lineCursorHeight: number;
5051
private _typicalHalfwidthCharacterWidth: number;
5152

5253
private _isVisible: boolean;
@@ -65,6 +66,7 @@ export class ViewCursor {
6566
this._cursorStyle = options.get(EditorOption.effectiveCursorStyle);
6667
this._typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth;
6768
this._lineCursorWidth = Math.min(options.get(EditorOption.cursorWidth), this._typicalHalfwidthCharacterWidth);
69+
this._lineCursorHeight = options.get(EditorOption.cursorHeight);
6870

6971
this._isVisible = true;
7072

@@ -131,6 +133,7 @@ export class ViewCursor {
131133
this._cursorStyle = options.get(EditorOption.effectiveCursorStyle);
132134
this._typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth;
133135
this._lineCursorWidth = Math.min(options.get(EditorOption.cursorWidth), this._typicalHalfwidthCharacterWidth);
136+
this._lineCursorHeight = options.get(EditorOption.cursorHeight);
134137
applyFontInfo(this._domNode, fontInfo);
135138

136139
return true;
@@ -161,6 +164,13 @@ export class ViewCursor {
161164
let textContent = '';
162165
let textContentClassName = '';
163166
const [position, nextGrapheme] = this._getGraphemeAwarePosition();
167+
const lineHeight = this._context.viewLayout.getLineHeightForLineNumber(position.lineNumber);
168+
const lineCursorHeight = (
169+
this._lineCursorHeight === 0
170+
? lineHeight // 0 indicates that the cursor should take the full line height
171+
: Math.min(lineHeight, this._lineCursorHeight)
172+
);
173+
const lineHeightAdjustment = (lineHeight - lineCursorHeight) / 2;
164174

165175
if (this._cursorStyle === TextEditorCursorStyle.Line || this._cursorStyle === TextEditorCursorStyle.LineThin) {
166176
const visibleRange = ctx.visibleRangeForPosition(position);
@@ -189,9 +199,8 @@ export class ViewCursor {
189199
left -= paddingLeft;
190200
}
191201

192-
const top = ctx.getVerticalOffsetForLineNumber(position.lineNumber) - ctx.bigNumbersDelta;
193-
const lineHeight = this._context.viewLayout.getLineHeightForLineNumber(position.lineNumber);
194-
return new ViewCursorRenderData(top, left, paddingLeft, width, lineHeight, textContent, textContentClassName);
202+
const top = ctx.getVerticalOffsetForLineNumber(position.lineNumber) - ctx.bigNumbersDelta + lineHeightAdjustment;
203+
return new ViewCursorRenderData(top, left, paddingLeft, width, lineCursorHeight, textContent, textContentClassName);
195204
}
196205

197206
const visibleRangeForCharacter = ctx.linesVisibleRangesForRange(new Range(position.lineNumber, position.column, position.lineNumber, position.column + nextGrapheme.length), false);
@@ -221,7 +230,6 @@ export class ViewCursor {
221230
}
222231

223232
let top = ctx.getVerticalOffsetForLineNumber(position.lineNumber) - ctx.bigNumbersDelta;
224-
const lineHeight = this._context.viewLayout.getLineHeightForLineNumber(position.lineNumber);
225233
let height = lineHeight;
226234

227235
// Underline might interfere with clicking

src/vs/editor/common/config/editorOptions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ export interface IEditorOptions {
272272
* Control the width of the cursor when cursorStyle is set to 'line'
273273
*/
274274
cursorWidth?: number;
275+
/**
276+
* Control the height of the cursor when cursorStyle is set to 'line'
277+
*/
278+
cursorHeight?: number;
275279
/**
276280
* Enable font ligatures.
277281
* Defaults to false.
@@ -5616,6 +5620,7 @@ export const enum EditorOption {
56165620
cursorSurroundingLines,
56175621
cursorSurroundingLinesStyle,
56185622
cursorWidth,
5623+
cursorHeight,
56195624
disableLayerHinting,
56205625
disableMonospaceOptimizations,
56215626
domReadOnly,
@@ -6026,6 +6031,11 @@ export const EditorOptions = {
60266031
0, 0, Constants.MAX_SAFE_SMALL_INTEGER,
60276032
{ markdownDescription: nls.localize('cursorWidth', "Controls the width of the cursor when `#editor.cursorStyle#` is set to `line`.") }
60286033
)),
6034+
cursorHeight: register(new EditorIntOption(
6035+
EditorOption.cursorHeight, 'cursorHeight',
6036+
0, 0, Constants.MAX_SAFE_SMALL_INTEGER,
6037+
{ markdownDescription: nls.localize('cursorHeight', "Controls the height of the cursor when `#editor.cursorStyle#` is set to `line`. Cursor's max height depends on line height.") }
6038+
)),
60296039
disableLayerHinting: register(new EditorBooleanOption(
60306040
EditorOption.disableLayerHinting, 'disableLayerHinting', false,
60316041
)),

src/vs/editor/common/standalone/standaloneEnums.ts

Lines changed: 132 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -212,137 +212,138 @@ export enum EditorOption {
212212
cursorSurroundingLines = 35,
213213
cursorSurroundingLinesStyle = 36,
214214
cursorWidth = 37,
215-
disableLayerHinting = 38,
216-
disableMonospaceOptimizations = 39,
217-
domReadOnly = 40,
218-
dragAndDrop = 41,
219-
dropIntoEditor = 42,
220-
editContext = 43,
221-
emptySelectionClipboard = 44,
222-
experimentalGpuAcceleration = 45,
223-
experimentalWhitespaceRendering = 46,
224-
extraEditorClassName = 47,
225-
fastScrollSensitivity = 48,
226-
find = 49,
227-
fixedOverflowWidgets = 50,
228-
folding = 51,
229-
foldingStrategy = 52,
230-
foldingHighlight = 53,
231-
foldingImportsByDefault = 54,
232-
foldingMaximumRegions = 55,
233-
unfoldOnClickAfterEndOfLine = 56,
234-
fontFamily = 57,
235-
fontInfo = 58,
236-
fontLigatures = 59,
237-
fontSize = 60,
238-
fontWeight = 61,
239-
fontVariations = 62,
240-
formatOnPaste = 63,
241-
formatOnType = 64,
242-
glyphMargin = 65,
243-
gotoLocation = 66,
244-
hideCursorInOverviewRuler = 67,
245-
hover = 68,
246-
inDiffEditor = 69,
247-
inlineSuggest = 70,
248-
letterSpacing = 71,
249-
lightbulb = 72,
250-
lineDecorationsWidth = 73,
251-
lineHeight = 74,
252-
lineNumbers = 75,
253-
lineNumbersMinChars = 76,
254-
linkedEditing = 77,
255-
links = 78,
256-
matchBrackets = 79,
257-
minimap = 80,
258-
mouseStyle = 81,
259-
mouseWheelScrollSensitivity = 82,
260-
mouseWheelZoom = 83,
261-
multiCursorMergeOverlapping = 84,
262-
multiCursorModifier = 85,
263-
multiCursorPaste = 86,
264-
multiCursorLimit = 87,
265-
occurrencesHighlight = 88,
266-
occurrencesHighlightDelay = 89,
267-
overtypeCursorStyle = 90,
268-
overtypeOnPaste = 91,
269-
overviewRulerBorder = 92,
270-
overviewRulerLanes = 93,
271-
padding = 94,
272-
pasteAs = 95,
273-
parameterHints = 96,
274-
peekWidgetDefaultFocus = 97,
275-
placeholder = 98,
276-
definitionLinkOpensInPeek = 99,
277-
quickSuggestions = 100,
278-
quickSuggestionsDelay = 101,
279-
readOnly = 102,
280-
readOnlyMessage = 103,
281-
renameOnType = 104,
282-
renderControlCharacters = 105,
283-
renderFinalNewline = 106,
284-
renderLineHighlight = 107,
285-
renderLineHighlightOnlyWhenFocus = 108,
286-
renderValidationDecorations = 109,
287-
renderWhitespace = 110,
288-
revealHorizontalRightPadding = 111,
289-
roundedSelection = 112,
290-
rulers = 113,
291-
scrollbar = 114,
292-
scrollBeyondLastColumn = 115,
293-
scrollBeyondLastLine = 116,
294-
scrollPredominantAxis = 117,
295-
selectionClipboard = 118,
296-
selectionHighlight = 119,
297-
selectionHighlightMaxLength = 120,
298-
selectionHighlightMultiline = 121,
299-
selectOnLineNumbers = 122,
300-
showFoldingControls = 123,
301-
showUnused = 124,
302-
snippetSuggestions = 125,
303-
smartSelect = 126,
304-
smoothScrolling = 127,
305-
stickyScroll = 128,
306-
stickyTabStops = 129,
307-
stopRenderingLineAfter = 130,
308-
suggest = 131,
309-
suggestFontSize = 132,
310-
suggestLineHeight = 133,
311-
suggestOnTriggerCharacters = 134,
312-
suggestSelection = 135,
313-
tabCompletion = 136,
314-
tabIndex = 137,
315-
unicodeHighlighting = 138,
316-
unusualLineTerminators = 139,
317-
useShadowDOM = 140,
318-
useTabStops = 141,
319-
wordBreak = 142,
320-
wordSegmenterLocales = 143,
321-
wordSeparators = 144,
322-
wordWrap = 145,
323-
wordWrapBreakAfterCharacters = 146,
324-
wordWrapBreakBeforeCharacters = 147,
325-
wordWrapColumn = 148,
326-
wordWrapOverride1 = 149,
327-
wordWrapOverride2 = 150,
328-
wrappingIndent = 151,
329-
wrappingStrategy = 152,
330-
showDeprecated = 153,
331-
inertialScroll = 154,
332-
inlayHints = 155,
333-
wrapOnEscapedLineFeeds = 156,
334-
effectiveCursorStyle = 157,
335-
editorClassName = 158,
336-
pixelRatio = 159,
337-
tabFocusMode = 160,
338-
layoutInfo = 161,
339-
wrappingInfo = 162,
340-
defaultColorDecorators = 163,
341-
colorDecoratorsActivatedOn = 164,
342-
inlineCompletionsAccessibilityVerbose = 165,
343-
effectiveEditContext = 166,
344-
scrollOnMiddleClick = 167,
345-
effectiveAllowVariableFonts = 168
215+
cursorHeight = 38,
216+
disableLayerHinting = 39,
217+
disableMonospaceOptimizations = 40,
218+
domReadOnly = 41,
219+
dragAndDrop = 42,
220+
dropIntoEditor = 43,
221+
editContext = 44,
222+
emptySelectionClipboard = 45,
223+
experimentalGpuAcceleration = 46,
224+
experimentalWhitespaceRendering = 47,
225+
extraEditorClassName = 48,
226+
fastScrollSensitivity = 49,
227+
find = 50,
228+
fixedOverflowWidgets = 51,
229+
folding = 52,
230+
foldingStrategy = 53,
231+
foldingHighlight = 54,
232+
foldingImportsByDefault = 55,
233+
foldingMaximumRegions = 56,
234+
unfoldOnClickAfterEndOfLine = 57,
235+
fontFamily = 58,
236+
fontInfo = 59,
237+
fontLigatures = 60,
238+
fontSize = 61,
239+
fontWeight = 62,
240+
fontVariations = 63,
241+
formatOnPaste = 64,
242+
formatOnType = 65,
243+
glyphMargin = 66,
244+
gotoLocation = 67,
245+
hideCursorInOverviewRuler = 68,
246+
hover = 69,
247+
inDiffEditor = 70,
248+
inlineSuggest = 71,
249+
letterSpacing = 72,
250+
lightbulb = 73,
251+
lineDecorationsWidth = 74,
252+
lineHeight = 75,
253+
lineNumbers = 76,
254+
lineNumbersMinChars = 77,
255+
linkedEditing = 78,
256+
links = 79,
257+
matchBrackets = 80,
258+
minimap = 81,
259+
mouseStyle = 82,
260+
mouseWheelScrollSensitivity = 83,
261+
mouseWheelZoom = 84,
262+
multiCursorMergeOverlapping = 85,
263+
multiCursorModifier = 86,
264+
multiCursorPaste = 87,
265+
multiCursorLimit = 88,
266+
occurrencesHighlight = 89,
267+
occurrencesHighlightDelay = 90,
268+
overtypeCursorStyle = 91,
269+
overtypeOnPaste = 92,
270+
overviewRulerBorder = 93,
271+
overviewRulerLanes = 94,
272+
padding = 95,
273+
pasteAs = 96,
274+
parameterHints = 97,
275+
peekWidgetDefaultFocus = 98,
276+
placeholder = 99,
277+
definitionLinkOpensInPeek = 100,
278+
quickSuggestions = 101,
279+
quickSuggestionsDelay = 102,
280+
readOnly = 103,
281+
readOnlyMessage = 104,
282+
renameOnType = 105,
283+
renderControlCharacters = 106,
284+
renderFinalNewline = 107,
285+
renderLineHighlight = 108,
286+
renderLineHighlightOnlyWhenFocus = 109,
287+
renderValidationDecorations = 110,
288+
renderWhitespace = 111,
289+
revealHorizontalRightPadding = 112,
290+
roundedSelection = 113,
291+
rulers = 114,
292+
scrollbar = 115,
293+
scrollBeyondLastColumn = 116,
294+
scrollBeyondLastLine = 117,
295+
scrollPredominantAxis = 118,
296+
selectionClipboard = 119,
297+
selectionHighlight = 120,
298+
selectionHighlightMaxLength = 121,
299+
selectionHighlightMultiline = 122,
300+
selectOnLineNumbers = 123,
301+
showFoldingControls = 124,
302+
showUnused = 125,
303+
snippetSuggestions = 126,
304+
smartSelect = 127,
305+
smoothScrolling = 128,
306+
stickyScroll = 129,
307+
stickyTabStops = 130,
308+
stopRenderingLineAfter = 131,
309+
suggest = 132,
310+
suggestFontSize = 133,
311+
suggestLineHeight = 134,
312+
suggestOnTriggerCharacters = 135,
313+
suggestSelection = 136,
314+
tabCompletion = 137,
315+
tabIndex = 138,
316+
unicodeHighlighting = 139,
317+
unusualLineTerminators = 140,
318+
useShadowDOM = 141,
319+
useTabStops = 142,
320+
wordBreak = 143,
321+
wordSegmenterLocales = 144,
322+
wordSeparators = 145,
323+
wordWrap = 146,
324+
wordWrapBreakAfterCharacters = 147,
325+
wordWrapBreakBeforeCharacters = 148,
326+
wordWrapColumn = 149,
327+
wordWrapOverride1 = 150,
328+
wordWrapOverride2 = 151,
329+
wrappingIndent = 152,
330+
wrappingStrategy = 153,
331+
showDeprecated = 154,
332+
inertialScroll = 155,
333+
inlayHints = 156,
334+
wrapOnEscapedLineFeeds = 157,
335+
effectiveCursorStyle = 158,
336+
editorClassName = 159,
337+
pixelRatio = 160,
338+
tabFocusMode = 161,
339+
layoutInfo = 162,
340+
wrappingInfo = 163,
341+
defaultColorDecorators = 164,
342+
colorDecoratorsActivatedOn = 165,
343+
inlineCompletionsAccessibilityVerbose = 166,
344+
effectiveEditContext = 167,
345+
scrollOnMiddleClick = 168,
346+
effectiveAllowVariableFonts = 169
346347
}
347348

348349
/**

0 commit comments

Comments
 (0)