add setting for code lens font family and size, https://github.com/microsoft/vscode/issues/16038

This commit is contained in:
Johannes Rieken
2020-11-09 21:56:14 +01:00
parent 5e8f9cf1d2
commit 51eb0901d4
5 changed files with 297 additions and 232 deletions
@@ -495,6 +495,14 @@ export interface IEditorOptions {
* Defaults to true.
*/
codeLens?: boolean;
/**
* Code lens font family. Defaults to editor font family.
*/
codeLensFontFamily?: string;
/**
* Code lens font size. Default to 90% of the editor font size
*/
codeLensFontSize?: number;
/**
* Control the behavior and rendering of the code action lightbulb.
*/
@@ -3619,6 +3627,8 @@ export const enum EditorOption {
automaticLayout,
autoSurround,
codeLens,
codeLensFontFamily,
codeLensFontSize,
colorDecorators,
columnSelection,
comments,
@@ -3848,6 +3858,17 @@ export const EditorOptions = {
EditorOption.codeLens, 'codeLens', true,
{ description: nls.localize('codeLens', "Controls whether the editor shows CodeLens.") }
)),
codeLensFontFamily: register(new EditorStringOption(
EditorOption.codeLensFontFamily, 'codeLensFontFamily', '',
{ description: nls.localize('codeLensFontFamily', "Controls the font family for CodeLens.") }
)),
codeLensFontSize: register(new EditorIntOption(EditorOption.codeLensFontSize, 'codeLensFontSize', 0, 0, 100, {
type: 'number',
default: 0,
minimum: 0,
maximum: 100,
description: nls.localize('codeLensFontSize', "Controls the font size in pixels for CodeLens. When set to `0`, the 90% of `#editor.fontSize#` is used.")
})),
colorDecorators: register(new EditorBooleanOption(
EditorOption.colorDecorators, 'colorDecorators', true,
{ description: nls.localize('colorDecorators', "Controls whether the editor should render the inline color decorators and color picker.") }
+110 -108
View File
@@ -179,114 +179,116 @@ export enum EditorOption {
automaticLayout = 9,
autoSurround = 10,
codeLens = 11,
colorDecorators = 12,
columnSelection = 13,
comments = 14,
contextmenu = 15,
copyWithSyntaxHighlighting = 16,
cursorBlinking = 17,
cursorSmoothCaretAnimation = 18,
cursorStyle = 19,
cursorSurroundingLines = 20,
cursorSurroundingLinesStyle = 21,
cursorWidth = 22,
disableLayerHinting = 23,
disableMonospaceOptimizations = 24,
dragAndDrop = 25,
emptySelectionClipboard = 26,
extraEditorClassName = 27,
fastScrollSensitivity = 28,
find = 29,
fixedOverflowWidgets = 30,
folding = 31,
foldingStrategy = 32,
foldingHighlight = 33,
unfoldOnClickAfterEndOfLine = 34,
fontFamily = 35,
fontInfo = 36,
fontLigatures = 37,
fontSize = 38,
fontWeight = 39,
formatOnPaste = 40,
formatOnType = 41,
glyphMargin = 42,
gotoLocation = 43,
hideCursorInOverviewRuler = 44,
highlightActiveIndentGuide = 45,
hover = 46,
inDiffEditor = 47,
letterSpacing = 48,
lightbulb = 49,
lineDecorationsWidth = 50,
lineHeight = 51,
lineNumbers = 52,
lineNumbersMinChars = 53,
links = 54,
matchBrackets = 55,
minimap = 56,
mouseStyle = 57,
mouseWheelScrollSensitivity = 58,
mouseWheelZoom = 59,
multiCursorMergeOverlapping = 60,
multiCursorModifier = 61,
multiCursorPaste = 62,
occurrencesHighlight = 63,
overviewRulerBorder = 64,
overviewRulerLanes = 65,
padding = 66,
parameterHints = 67,
peekWidgetDefaultFocus = 68,
definitionLinkOpensInPeek = 69,
quickSuggestions = 70,
quickSuggestionsDelay = 71,
readOnly = 72,
renameOnType = 73,
renderControlCharacters = 74,
renderIndentGuides = 75,
renderFinalNewline = 76,
renderLineHighlight = 77,
renderLineHighlightOnlyWhenFocus = 78,
renderValidationDecorations = 79,
renderWhitespace = 80,
revealHorizontalRightPadding = 81,
roundedSelection = 82,
rulers = 83,
scrollbar = 84,
scrollBeyondLastColumn = 85,
scrollBeyondLastLine = 86,
scrollPredominantAxis = 87,
selectionClipboard = 88,
selectionHighlight = 89,
selectOnLineNumbers = 90,
showFoldingControls = 91,
showUnused = 92,
snippetSuggestions = 93,
smartSelect = 94,
smoothScrolling = 95,
stopRenderingLineAfter = 96,
suggest = 97,
suggestFontSize = 98,
suggestLineHeight = 99,
suggestOnTriggerCharacters = 100,
suggestSelection = 101,
tabCompletion = 102,
tabIndex = 103,
unusualLineTerminators = 104,
useTabStops = 105,
wordSeparators = 106,
wordWrap = 107,
wordWrapBreakAfterCharacters = 108,
wordWrapBreakBeforeCharacters = 109,
wordWrapColumn = 110,
wordWrapMinified = 111,
wrappingIndent = 112,
wrappingStrategy = 113,
showDeprecated = 114,
editorClassName = 115,
pixelRatio = 116,
tabFocusMode = 117,
layoutInfo = 118,
wrappingInfo = 119
codeLensFontFamily = 12,
codeLensFontSize = 13,
colorDecorators = 14,
columnSelection = 15,
comments = 16,
contextmenu = 17,
copyWithSyntaxHighlighting = 18,
cursorBlinking = 19,
cursorSmoothCaretAnimation = 20,
cursorStyle = 21,
cursorSurroundingLines = 22,
cursorSurroundingLinesStyle = 23,
cursorWidth = 24,
disableLayerHinting = 25,
disableMonospaceOptimizations = 26,
dragAndDrop = 27,
emptySelectionClipboard = 28,
extraEditorClassName = 29,
fastScrollSensitivity = 30,
find = 31,
fixedOverflowWidgets = 32,
folding = 33,
foldingStrategy = 34,
foldingHighlight = 35,
unfoldOnClickAfterEndOfLine = 36,
fontFamily = 37,
fontInfo = 38,
fontLigatures = 39,
fontSize = 40,
fontWeight = 41,
formatOnPaste = 42,
formatOnType = 43,
glyphMargin = 44,
gotoLocation = 45,
hideCursorInOverviewRuler = 46,
highlightActiveIndentGuide = 47,
hover = 48,
inDiffEditor = 49,
letterSpacing = 50,
lightbulb = 51,
lineDecorationsWidth = 52,
lineHeight = 53,
lineNumbers = 54,
lineNumbersMinChars = 55,
links = 56,
matchBrackets = 57,
minimap = 58,
mouseStyle = 59,
mouseWheelScrollSensitivity = 60,
mouseWheelZoom = 61,
multiCursorMergeOverlapping = 62,
multiCursorModifier = 63,
multiCursorPaste = 64,
occurrencesHighlight = 65,
overviewRulerBorder = 66,
overviewRulerLanes = 67,
padding = 68,
parameterHints = 69,
peekWidgetDefaultFocus = 70,
definitionLinkOpensInPeek = 71,
quickSuggestions = 72,
quickSuggestionsDelay = 73,
readOnly = 74,
renameOnType = 75,
renderControlCharacters = 76,
renderIndentGuides = 77,
renderFinalNewline = 78,
renderLineHighlight = 79,
renderLineHighlightOnlyWhenFocus = 80,
renderValidationDecorations = 81,
renderWhitespace = 82,
revealHorizontalRightPadding = 83,
roundedSelection = 84,
rulers = 85,
scrollbar = 86,
scrollBeyondLastColumn = 87,
scrollBeyondLastLine = 88,
scrollPredominantAxis = 89,
selectionClipboard = 90,
selectionHighlight = 91,
selectOnLineNumbers = 92,
showFoldingControls = 93,
showUnused = 94,
snippetSuggestions = 95,
smartSelect = 96,
smoothScrolling = 97,
stopRenderingLineAfter = 98,
suggest = 99,
suggestFontSize = 100,
suggestLineHeight = 101,
suggestOnTriggerCharacters = 102,
suggestSelection = 103,
tabCompletion = 104,
tabIndex = 105,
unusualLineTerminators = 106,
useTabStops = 107,
wordSeparators = 108,
wordWrap = 109,
wordWrapBreakAfterCharacters = 110,
wordWrapBreakBeforeCharacters = 111,
wordWrapColumn = 112,
wordWrapMinified = 113,
wrappingIndent = 114,
wrappingStrategy = 115,
showDeprecated = 116,
editorClassName = 117,
pixelRatio = 118,
tabFocusMode = 119,
layoutInfo = 120,
wrappingInfo = 121
}
/**
@@ -53,7 +53,7 @@ export class CodeLensContribution implements IEditorContribution {
this._disposables.add(this._editor.onDidChangeModel(() => this._onModelChange()));
this._disposables.add(this._editor.onDidChangeModelLanguage(() => this._onModelChange()));
this._disposables.add(this._editor.onDidChangeConfiguration((e) => {
if (e.hasChanged(EditorOption.fontInfo)) {
if (e.hasChanged(EditorOption.fontInfo) || e.hasChanged(EditorOption.codeLensFontSize) || e.hasChanged(EditorOption.codeLensFontFamily)) {
this._updateLensStyle();
}
if (e.hasChanged(EditorOption.codeLens)) {
@@ -77,21 +77,41 @@ export class CodeLensContribution implements IEditorContribution {
this._disposables.dispose();
this._oldCodeLensModels.dispose();
this._currentCodeLensModel?.dispose();
this._styleElement.remove();
}
private _getLayoutInfo() {
let fontSize = this._editor.getOption(EditorOption.codeLensFontSize);
let codeLensHeight: number;
if (!fontSize || fontSize < 5) {
fontSize = (this._editor.getOption(EditorOption.fontSize) * .9) | 0;
codeLensHeight = this._editor.getOption(EditorOption.lineHeight);
} else {
codeLensHeight = (fontSize * Math.max(1.3, this._editor.getOption(EditorOption.lineHeight) / this._editor.getOption(EditorOption.fontSize))) | 0;
}
return { codeLensHeight, fontSize };
}
private _updateLensStyle(): void {
const options = this._editor.getOptions();
const fontInfo = options.get(EditorOption.fontInfo);
const lineHeight = options.get(EditorOption.lineHeight);
const { codeLensHeight, fontSize } = this._getLayoutInfo();
const fontFamily = this._editor.getOption(EditorOption.codeLensFontFamily);
const height = Math.round(lineHeight * 1.1);
const fontSize = Math.round(fontInfo.fontSize * 0.9);
const newStyle = `
.monaco-editor .codelens-decoration.${this._styleClassName} { height: ${height}px; line-height: ${lineHeight}px; font-size: ${fontSize}px; padding-right: ${Math.round(fontInfo.fontSize * 0.45)}px;}
.monaco-editor .codelens-decoration.${this._styleClassName} > a > .codicon { line-height: ${lineHeight}px; font-size: ${fontSize}px; }
let newStyle = `
.monaco-editor .codelens-decoration.${this._styleClassName} { line-height: ${codeLensHeight}px; font-size: ${fontSize}px; padding-right: ${Math.round(fontSize * 0.5)}px;}
.monaco-editor .codelens-decoration.${this._styleClassName} > a > .codicon { line-height: ${codeLensHeight}px; font-size: ${fontSize}px; }
`;
if (fontFamily) {
newStyle += `.monaco-editor .codelens-decoration.${this._styleClassName} { font-family: ${fontFamily}}`;
}
this._styleElement.textContent = newStyle;
//
this._editor.changeViewZones(accessor => {
for (let lens of this._lenses) {
lens.updateHeight(codeLensHeight, accessor);
}
});
}
private _localDispose(): void {
@@ -283,6 +303,7 @@ export class CodeLensContribution implements IEditorContribution {
}
const scrollState = StableEditorScrollState.capture(this._editor);
const layoutInfo = this._getLayoutInfo();
this._editor.changeDecorations(decorationsAccessor => {
this._editor.changeViewZones(viewZoneAccessor => {
@@ -304,7 +325,7 @@ export class CodeLensContribution implements IEditorContribution {
groupsIndex++;
codeLensIndex++;
} else {
this._lenses.splice(codeLensIndex, 0, new CodeLensWidget(groups[groupsIndex], <IActiveCodeEditor>this._editor, this._styleClassName, helper, viewZoneAccessor, () => this._resolveCodeLensesInViewportSoon()));
this._lenses.splice(codeLensIndex, 0, new CodeLensWidget(groups[groupsIndex], <IActiveCodeEditor>this._editor, this._styleClassName, helper, viewZoneAccessor, layoutInfo.codeLensHeight, () => this._resolveCodeLensesInViewportSoon()));
codeLensIndex++;
groupsIndex++;
}
@@ -318,7 +339,7 @@ export class CodeLensContribution implements IEditorContribution {
// Create extra symbols
while (groupsIndex < groups.length) {
this._lenses.push(new CodeLensWidget(groups[groupsIndex], <IActiveCodeEditor>this._editor, this._styleClassName, helper, viewZoneAccessor, () => this._resolveCodeLensesInViewportSoon()));
this._lenses.push(new CodeLensWidget(groups[groupsIndex], <IActiveCodeEditor>this._editor, this._styleClassName, helper, viewZoneAccessor, layoutInfo.codeLensHeight, () => this._resolveCodeLensesInViewportSoon()));
groupsIndex++;
}
@@ -18,20 +18,20 @@ import { renderCodicons } from 'vs/base/browser/codicons';
class CodeLensViewZone implements IViewZone {
readonly heightInLines: number;
readonly suppressMouseDown: boolean;
readonly domNode: HTMLElement;
afterLineNumber: number;
heightInPx: number;
private _lastHeight?: number;
private readonly _onHeight: () => void;
constructor(afterLineNumber: number, onHeight: () => void) {
constructor(afterLineNumber: number, heightInPx: number, onHeight: () => void) {
this.afterLineNumber = afterLineNumber;
this._onHeight = onHeight;
this.heightInPx = heightInPx;
this.heightInLines = 1;
this._onHeight = onHeight;
this.suppressMouseDown = true;
this.domNode = document.createElement('div');
}
@@ -193,6 +193,7 @@ export class CodeLensWidget {
className: string,
helper: CodeLensHelper,
viewZoneChangeAccessor: IViewZoneChangeAccessor,
heightInPx: number,
updateCallback: () => void
) {
this._editor = editor;
@@ -224,7 +225,7 @@ export class CodeLensWidget {
}
});
this._viewZone = new CodeLensViewZone(range!.startLineNumber - 1, updateCallback);
this._viewZone = new CodeLensViewZone(range!.startLineNumber - 1, heightInPx, updateCallback);
this._viewZoneId = viewZoneChangeAccessor.addZone(this._viewZone);
if (lenses.length > 0) {
@@ -277,6 +278,14 @@ export class CodeLensWidget {
});
}
updateHeight(height: number, viewZoneChangeAccessor: IViewZoneChangeAccessor): void {
this._viewZone.heightInPx = height;
viewZoneChangeAccessor.layoutZone(this._viewZoneId);
if (this._contentWidget) {
this._editor.layoutContentWidget(this._contentWidget);
}
}
computeIfNecessary(model: ITextModel): CodeLensItem[] | null {
if (!this._viewZone.domNode.hasAttribute('monaco-visible-view-zone')) {
return null;
+120 -108
View File
@@ -3034,6 +3034,14 @@ declare namespace monaco.editor {
* Defaults to true.
*/
codeLens?: boolean;
/**
* Code lens font family. Defaults to editor font family.
*/
codeLensFontFamily?: string;
/**
* Code lens font size. Default to 90% of the editor font size
*/
codeLensFontSize?: number;
/**
* Control the behavior and rendering of the code action lightbulb.
*/
@@ -3884,114 +3892,116 @@ declare namespace monaco.editor {
automaticLayout = 9,
autoSurround = 10,
codeLens = 11,
colorDecorators = 12,
columnSelection = 13,
comments = 14,
contextmenu = 15,
copyWithSyntaxHighlighting = 16,
cursorBlinking = 17,
cursorSmoothCaretAnimation = 18,
cursorStyle = 19,
cursorSurroundingLines = 20,
cursorSurroundingLinesStyle = 21,
cursorWidth = 22,
disableLayerHinting = 23,
disableMonospaceOptimizations = 24,
dragAndDrop = 25,
emptySelectionClipboard = 26,
extraEditorClassName = 27,
fastScrollSensitivity = 28,
find = 29,
fixedOverflowWidgets = 30,
folding = 31,
foldingStrategy = 32,
foldingHighlight = 33,
unfoldOnClickAfterEndOfLine = 34,
fontFamily = 35,
fontInfo = 36,
fontLigatures = 37,
fontSize = 38,
fontWeight = 39,
formatOnPaste = 40,
formatOnType = 41,
glyphMargin = 42,
gotoLocation = 43,
hideCursorInOverviewRuler = 44,
highlightActiveIndentGuide = 45,
hover = 46,
inDiffEditor = 47,
letterSpacing = 48,
lightbulb = 49,
lineDecorationsWidth = 50,
lineHeight = 51,
lineNumbers = 52,
lineNumbersMinChars = 53,
links = 54,
matchBrackets = 55,
minimap = 56,
mouseStyle = 57,
mouseWheelScrollSensitivity = 58,
mouseWheelZoom = 59,
multiCursorMergeOverlapping = 60,
multiCursorModifier = 61,
multiCursorPaste = 62,
occurrencesHighlight = 63,
overviewRulerBorder = 64,
overviewRulerLanes = 65,
padding = 66,
parameterHints = 67,
peekWidgetDefaultFocus = 68,
definitionLinkOpensInPeek = 69,
quickSuggestions = 70,
quickSuggestionsDelay = 71,
readOnly = 72,
renameOnType = 73,
renderControlCharacters = 74,
renderIndentGuides = 75,
renderFinalNewline = 76,
renderLineHighlight = 77,
renderLineHighlightOnlyWhenFocus = 78,
renderValidationDecorations = 79,
renderWhitespace = 80,
revealHorizontalRightPadding = 81,
roundedSelection = 82,
rulers = 83,
scrollbar = 84,
scrollBeyondLastColumn = 85,
scrollBeyondLastLine = 86,
scrollPredominantAxis = 87,
selectionClipboard = 88,
selectionHighlight = 89,
selectOnLineNumbers = 90,
showFoldingControls = 91,
showUnused = 92,
snippetSuggestions = 93,
smartSelect = 94,
smoothScrolling = 95,
stopRenderingLineAfter = 96,
suggest = 97,
suggestFontSize = 98,
suggestLineHeight = 99,
suggestOnTriggerCharacters = 100,
suggestSelection = 101,
tabCompletion = 102,
tabIndex = 103,
unusualLineTerminators = 104,
useTabStops = 105,
wordSeparators = 106,
wordWrap = 107,
wordWrapBreakAfterCharacters = 108,
wordWrapBreakBeforeCharacters = 109,
wordWrapColumn = 110,
wordWrapMinified = 111,
wrappingIndent = 112,
wrappingStrategy = 113,
showDeprecated = 114,
editorClassName = 115,
pixelRatio = 116,
tabFocusMode = 117,
layoutInfo = 118,
wrappingInfo = 119
codeLensFontFamily = 12,
codeLensFontSize = 13,
colorDecorators = 14,
columnSelection = 15,
comments = 16,
contextmenu = 17,
copyWithSyntaxHighlighting = 18,
cursorBlinking = 19,
cursorSmoothCaretAnimation = 20,
cursorStyle = 21,
cursorSurroundingLines = 22,
cursorSurroundingLinesStyle = 23,
cursorWidth = 24,
disableLayerHinting = 25,
disableMonospaceOptimizations = 26,
dragAndDrop = 27,
emptySelectionClipboard = 28,
extraEditorClassName = 29,
fastScrollSensitivity = 30,
find = 31,
fixedOverflowWidgets = 32,
folding = 33,
foldingStrategy = 34,
foldingHighlight = 35,
unfoldOnClickAfterEndOfLine = 36,
fontFamily = 37,
fontInfo = 38,
fontLigatures = 39,
fontSize = 40,
fontWeight = 41,
formatOnPaste = 42,
formatOnType = 43,
glyphMargin = 44,
gotoLocation = 45,
hideCursorInOverviewRuler = 46,
highlightActiveIndentGuide = 47,
hover = 48,
inDiffEditor = 49,
letterSpacing = 50,
lightbulb = 51,
lineDecorationsWidth = 52,
lineHeight = 53,
lineNumbers = 54,
lineNumbersMinChars = 55,
links = 56,
matchBrackets = 57,
minimap = 58,
mouseStyle = 59,
mouseWheelScrollSensitivity = 60,
mouseWheelZoom = 61,
multiCursorMergeOverlapping = 62,
multiCursorModifier = 63,
multiCursorPaste = 64,
occurrencesHighlight = 65,
overviewRulerBorder = 66,
overviewRulerLanes = 67,
padding = 68,
parameterHints = 69,
peekWidgetDefaultFocus = 70,
definitionLinkOpensInPeek = 71,
quickSuggestions = 72,
quickSuggestionsDelay = 73,
readOnly = 74,
renameOnType = 75,
renderControlCharacters = 76,
renderIndentGuides = 77,
renderFinalNewline = 78,
renderLineHighlight = 79,
renderLineHighlightOnlyWhenFocus = 80,
renderValidationDecorations = 81,
renderWhitespace = 82,
revealHorizontalRightPadding = 83,
roundedSelection = 84,
rulers = 85,
scrollbar = 86,
scrollBeyondLastColumn = 87,
scrollBeyondLastLine = 88,
scrollPredominantAxis = 89,
selectionClipboard = 90,
selectionHighlight = 91,
selectOnLineNumbers = 92,
showFoldingControls = 93,
showUnused = 94,
snippetSuggestions = 95,
smartSelect = 96,
smoothScrolling = 97,
stopRenderingLineAfter = 98,
suggest = 99,
suggestFontSize = 100,
suggestLineHeight = 101,
suggestOnTriggerCharacters = 102,
suggestSelection = 103,
tabCompletion = 104,
tabIndex = 105,
unusualLineTerminators = 106,
useTabStops = 107,
wordSeparators = 108,
wordWrap = 109,
wordWrapBreakAfterCharacters = 110,
wordWrapBreakBeforeCharacters = 111,
wordWrapColumn = 112,
wordWrapMinified = 113,
wrappingIndent = 114,
wrappingStrategy = 115,
showDeprecated = 116,
editorClassName = 117,
pixelRatio = 118,
tabFocusMode = 119,
layoutInfo = 120,
wrappingInfo = 121
}
export const EditorOptions: {
acceptSuggestionOnCommitCharacter: IEditorOption<EditorOption.acceptSuggestionOnCommitCharacter, boolean>;
@@ -4006,6 +4016,8 @@ declare namespace monaco.editor {
automaticLayout: IEditorOption<EditorOption.automaticLayout, boolean>;
autoSurround: IEditorOption<EditorOption.autoSurround, EditorAutoSurroundStrategy>;
codeLens: IEditorOption<EditorOption.codeLens, boolean>;
codeLensFontFamily: IEditorOption<EditorOption.codeLensFontFamily, string>;
codeLensFontSize: IEditorOption<EditorOption.codeLensFontSize, number>;
colorDecorators: IEditorOption<EditorOption.colorDecorators, boolean>;
columnSelection: IEditorOption<EditorOption.columnSelection, boolean>;
comments: IEditorOption<EditorOption.comments, EditorCommentsOptions>;