Skip to content

Commit

Permalink
Change the default of editor.renderFinalNewline to dimmed on Linux (
Browse files Browse the repository at this point in the history
#168220)

Fixes #141169: Change the default of `editor.renderFinalNewline` to `dimmed` on Linux
  • Loading branch information
alexdima authored Dec 6, 2022
1 parent 2b642e1 commit 94acd2c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/vs/editor/browser/config/migrateOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ registerSimpleEditorSettingMigration('hover', [[true, { enabled: true }], [false
registerSimpleEditorSettingMigration('parameterHints', [[true, { enabled: true }], [false, { enabled: false }]]);
registerSimpleEditorSettingMigration('autoIndent', [[false, 'advanced'], [true, 'full']]);
registerSimpleEditorSettingMigration('matchBrackets', [[true, 'always'], [false, 'never']]);
registerSimpleEditorSettingMigration('renderFinalNewline', [[true, 'on'], [false, 'off']]);

registerEditorSettingMigration('autoClosingBrackets', (value, read, write) => {
if (value === false) {
Expand Down
58 changes: 34 additions & 24 deletions src/vs/editor/browser/viewParts/lineNumbers/lineNumbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { Position } from 'vs/editor/common/core/position';
import { RenderingContext } from 'vs/editor/browser/view/renderingContext';
import { ViewContext } from 'vs/editor/common/viewModel/viewContext';
import * as viewEvents from 'vs/editor/common/viewEvents';
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { editorDimmedLineNumber, editorLineNumbers } from 'vs/editor/common/core/editorColorRegistry';

export class LineNumbersOverlay extends DynamicViewOverlay {

Expand All @@ -21,7 +23,7 @@ export class LineNumbersOverlay extends DynamicViewOverlay {
private _lineHeight!: number;
private _renderLineNumbers!: RenderLineNumbersType;
private _renderCustomLineNumbers!: ((lineNumber: number) => string) | null;
private _renderFinalNewline!: boolean;
private _renderFinalNewline!: 'off' | 'on' | 'dimmed';
private _lineNumbersLeft!: number;
private _lineNumbersWidth!: number;
private _lastCursorModelPosition: Position;
Expand Down Expand Up @@ -140,40 +142,38 @@ export class LineNumbersOverlay extends DynamicViewOverlay {
const lineHeightClassName = (platform.isLinux ? (this._lineHeight % 2 === 0 ? ' lh-even' : ' lh-odd') : '');
const visibleStartLineNumber = ctx.visibleRange.startLineNumber;
const visibleEndLineNumber = ctx.visibleRange.endLineNumber;
const common = '<div class="' + LineNumbersOverlay.CLASS_NAME + lineHeightClassName + '" style="left:' + this._lineNumbersLeft + 'px;width:' + this._lineNumbersWidth + 'px;">';

const lineCount = this._context.viewModel.getLineCount();
const output: string[] = [];
for (let lineNumber = visibleStartLineNumber; lineNumber <= visibleEndLineNumber; lineNumber++) {
const lineIndex = lineNumber - visibleStartLineNumber;

if (!this._renderFinalNewline) {
if (lineNumber === lineCount && this._context.viewModel.getLineLength(lineNumber) === 0) {
// Do not render last (empty) line
output[lineIndex] = '';
continue;
}
const renderLineNumber = this._getLineRenderLineNumber(lineNumber);

if (!renderLineNumber) {
output[lineIndex] = '';
continue;
}

const renderLineNumber = this._getLineRenderLineNumber(lineNumber);
let extraClassName = '';

if (renderLineNumber) {
if (lineNumber === this._activeLineNumber) {
output[lineIndex] = (
'<div class="active-line-number ' + LineNumbersOverlay.CLASS_NAME + lineHeightClassName + '" style="left:' + this._lineNumbersLeft + 'px;width:' + this._lineNumbersWidth + 'px;">'
+ renderLineNumber
+ '</div>'
);
} else {
output[lineIndex] = (
common
+ renderLineNumber
+ '</div>'
);
if (lineNumber === lineCount && this._context.viewModel.getLineLength(lineNumber) === 0) {
// this is the last line
if (this._renderFinalNewline === 'off') {
output[lineIndex] = '';
continue;
}
} else {
output[lineIndex] = '';
if (this._renderFinalNewline === 'dimmed') {
extraClassName = ' dimmed-line-number';
}
}
if (lineNumber === this._activeLineNumber) {
extraClassName = ' active-line-number';
}

output[lineIndex] = (
`<div class="${LineNumbersOverlay.CLASS_NAME}${lineHeightClassName}${extraClassName}" style="left:${this._lineNumbersLeft}px;width:${this._lineNumbersWidth}px;">${renderLineNumber}</div>`
);
}

this._renderResult = output;
Expand All @@ -190,3 +190,13 @@ export class LineNumbersOverlay extends DynamicViewOverlay {
return this._renderResult[lineIndex];
}
}

registerThemingParticipant((theme, collector) => {
const editorLineNumbersColor = theme.getColor(editorLineNumbers);
const editorDimmedLineNumberColor = theme.getColor(editorDimmedLineNumber);
if (editorDimmedLineNumberColor) {
collector.addRule(`.monaco-editor .line-numbers.dimmed-line-number { color: ${editorDimmedLineNumberColor}; }`);
} else if (editorLineNumbersColor) {
collector.addRule(`.monaco-editor .line-numbers.dimmed-line-number { color: ${editorLineNumbersColor.transparent(0.4)}; }`);
}
});
10 changes: 6 additions & 4 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ export interface IEditorOptions {
cursorSurroundingLinesStyle?: 'default' | 'all';
/**
* Render last line number when the file ends with a newline.
* Defaults to true.
* Defaults to 'on' for Windows and macOS and 'dimmed' for Linux.
*/
renderFinalNewline?: boolean;
renderFinalNewline?: 'on' | 'off' | 'dimmed';
/**
* Remove unusual line terminators like LINE SEPARATOR (LS), PARAGRAPH SEPARATOR (PS).
* Defaults to 'prompt'.
Expand Down Expand Up @@ -5262,8 +5262,10 @@ export const EditorOptions = {
EditorOption.renderControlCharacters, 'renderControlCharacters', true,
{ description: nls.localize('renderControlCharacters', "Controls whether the editor should render control characters."), restricted: true }
)),
renderFinalNewline: register(new EditorBooleanOption(
EditorOption.renderFinalNewline, 'renderFinalNewline', true,
renderFinalNewline: register(new EditorStringEnumOption(
EditorOption.renderFinalNewline, 'renderFinalNewline',
(platform.isLinux ? 'dimmed' : 'on') as 'off' | 'on' | 'dimmed',
['off', 'on', 'dimmed'] as const,
{ description: nls.localize('renderFinalNewline', "Render last line number when the file ends with a newline.") }
)),
renderLineHighlight: register(new EditorStringEnumOption(
Expand Down
1 change: 1 addition & 0 deletions src/vs/editor/common/core/editorColorRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const editorLineNumbers = registerColor('editorLineNumber.foreground', {

const deprecatedEditorActiveLineNumber = registerColor('editorActiveLineNumber.foreground', { dark: '#c6c6c6', light: '#0B216F', hcDark: activeContrastBorder, hcLight: activeContrastBorder }, nls.localize('editorActiveLineNumber', 'Color of editor active line number'), false, nls.localize('deprecatedEditorActiveLineNumber', 'Id is deprecated. Use \'editorLineNumber.activeForeground\' instead.'));
export const editorActiveLineNumber = registerColor('editorLineNumber.activeForeground', { dark: deprecatedEditorActiveLineNumber, light: deprecatedEditorActiveLineNumber, hcDark: deprecatedEditorActiveLineNumber, hcLight: deprecatedEditorActiveLineNumber }, nls.localize('editorActiveLineNumber', 'Color of editor active line number'));
export const editorDimmedLineNumber = registerColor('editorLineNumber.dimmedForeground', { dark: null, light: null, hcDark: null, hcLight: null }, nls.localize('editorDimmedLineNumber', 'Color of the final editor line when editor.renderFinalNewline is set to dimmed.'));

export const editorRuler = registerColor('editorRuler.foreground', { dark: '#5A5A5A', light: Color.lightgrey, hcDark: Color.white, hcLight: '#292929' }, nls.localize('editorRuler', 'Color of the editor rulers.'));

Expand Down
6 changes: 3 additions & 3 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3058,9 +3058,9 @@ declare namespace monaco.editor {
cursorSurroundingLinesStyle?: 'default' | 'all';
/**
* Render last line number when the file ends with a newline.
* Defaults to true.
* Defaults to 'on' for Windows and macOS and 'dimmed' for Linux.
*/
renderFinalNewline?: boolean;
renderFinalNewline?: 'on' | 'off' | 'dimmed';
/**
* Remove unusual line terminators like LINE SEPARATOR (LS), PARAGRAPH SEPARATOR (PS).
* Defaults to 'prompt'.
Expand Down Expand Up @@ -4787,7 +4787,7 @@ declare namespace monaco.editor {
readOnly: IEditorOption<EditorOption.readOnly, boolean>;
renameOnType: IEditorOption<EditorOption.renameOnType, boolean>;
renderControlCharacters: IEditorOption<EditorOption.renderControlCharacters, boolean>;
renderFinalNewline: IEditorOption<EditorOption.renderFinalNewline, boolean>;
renderFinalNewline: IEditorOption<EditorOption.renderFinalNewline, 'on' | 'off' | 'dimmed'>;
renderLineHighlight: IEditorOption<EditorOption.renderLineHighlight, 'all' | 'line' | 'none' | 'gutter'>;
renderLineHighlightOnlyWhenFocus: IEditorOption<EditorOption.renderLineHighlightOnlyWhenFocus, boolean>;
renderValidationDecorations: IEditorOption<EditorOption.renderValidationDecorations, 'on' | 'off' | 'editable'>;
Expand Down

0 comments on commit 94acd2c

Please sign in to comment.