Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{ "editor.wrappingIndent": "deepIndent" } for 2 additional tabs on continuation lines #50542

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/vs/editor/common/config/commonEditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ const editorConfiguration: IConfigurationNode = {
},
'editor.wrappingIndent': {
'type': 'string',
'enum': ['none', 'same', 'indent'],
'enum': ['none', 'same', 'indent', 'deepIndent'],
'default': 'same',
'description': nls.localize('wrappingIndent', "Controls the indentation of wrapped lines. Can be one of 'none', 'same' or 'indent'.")
'description': nls.localize('wrappingIndent', "Controls the indentation of wrapped lines. Can be one of 'none', 'same', 'indent' or 'deepIndent'.")
},
'editor.mouseWheelScrollSensitivity': {
'type': 'number',
Expand Down
18 changes: 12 additions & 6 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export interface IEditorOptions {
*/
wordWrapMinified?: boolean;
/**
* Control indentation of wrapped lines. Can be: 'none', 'same' or 'indent'.
* Control indentation of wrapped lines. Can be: 'none', 'same', 'indent' or 'deepIndent'.
* Defaults to 'same' in vscode and to 'none' in monaco-editor.
*/
wrappingIndent?: string;
Expand Down Expand Up @@ -635,9 +635,13 @@ export enum WrappingIndent {
*/
Same = 1,
/**
* Indent => wrapped lines get +1 indentation as the parent.
* Indent => wrapped lines get +1 indentation toward the parent.
*/
Indent = 2
Indent = 2,
/**
* DeepIndent => wrapped lines get +2 indentation toward the parent.
*/
DeepIndent = 3
}

/**
Expand Down Expand Up @@ -1477,10 +1481,12 @@ function _wrappingIndentFromString(wrappingIndent: string, defaultValue: Wrappin
if (typeof wrappingIndent !== 'string') {
return defaultValue;
}
if (wrappingIndent === 'indent') {
return WrappingIndent.Indent;
} else if (wrappingIndent === 'same') {
if (wrappingIndent === 'same') {
return WrappingIndent.Same;
} else if (wrappingIndent === 'indent') {
return WrappingIndent.Indent;
} else if (wrappingIndent === 'deepIndent') {
return WrappingIndent.DeepIndent;
} else {
return WrappingIndent.None;
}
Expand Down
10 changes: 10 additions & 0 deletions src/vs/editor/common/viewModel/characterHardWrappingLineMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,24 @@ export class CharacterHardWrappingLineMapperFactory implements ILineMapperFactor
if (hardWrappingIndent !== WrappingIndent.None) {
firstNonWhitespaceIndex = strings.firstNonWhitespaceIndex(lineText);
if (firstNonWhitespaceIndex !== -1) {
// Track existing indent
wrappedTextIndent = lineText.substring(0, firstNonWhitespaceIndex);
for (let i = 0; i < firstNonWhitespaceIndex; i++) {
wrappedTextIndentVisibleColumn = CharacterHardWrappingLineMapperFactory.nextVisibleColumn(wrappedTextIndentVisibleColumn, tabSize, lineText.charCodeAt(i) === CharCode.Tab, 1);
}

// Increase indent of continuation lines, if desired
let numberOfAdditionalTabs = 0;
if (hardWrappingIndent === WrappingIndent.Indent) {
numberOfAdditionalTabs = 1;
} else if (hardWrappingIndent === WrappingIndent.DeepIndent) {
numberOfAdditionalTabs = 2;
}
for (let i = 0; i < numberOfAdditionalTabs; i++) {
wrappedTextIndent += '\t';
wrappedTextIndentVisibleColumn = CharacterHardWrappingLineMapperFactory.nextVisibleColumn(wrappedTextIndentVisibleColumn, tabSize, true, 1);
}

// Force sticking to beginning of line if no character would fit except for the indentation
if (wrappedTextIndentVisibleColumn + columnsForFullWidthChar > breakingColumn) {
wrappedTextIndent = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CharacterHardWrappingLineMapperFactory } from 'vs/editor/common/viewMod
import { ILineMapperFactory, ILineMapping } from 'vs/editor/common/viewModel/splitLinesCollection';

function assertLineMapping(factory: ILineMapperFactory, tabSize: number, breakAfter: number, annotatedText: string, wrappingIndent = WrappingIndent.None): ILineMapping {

// Create version of `annotatedText` with line break markers removed
let rawText = '';
let currentLineIndex = 0;
let lineIndices: number[] = [];
Expand All @@ -25,6 +25,7 @@ function assertLineMapping(factory: ILineMapperFactory, tabSize: number, breakAf

let mapper = factory.createLineMapping(rawText, tabSize, breakAfter, 2, wrappingIndent);

// Insert line break markers again, according to algorithm
let actualAnnotatedText = '';
if (mapper) {
let previousLineIndex = 0;
Expand Down Expand Up @@ -114,4 +115,10 @@ suite('Editor ViewModel - CharacterHardWrappingLineMapper', () => {
let mapper = assertLineMapping(factory, 4, 24, ' t h i s |i s |a l |o n |g l |i n |e', WrappingIndent.Indent);
assert.equal(mapper.getWrappedLinesIndent(), ' \t');
});

test('CharacterHardWrappingLineMapper - WrappingIndent.DeepIndent', () => {
let factory = new CharacterHardWrappingLineMapperFactory('', ' ', '');
let mapper = assertLineMapping(factory, 4, 26, ' W e A r e T e s t |i n g D e |e p I n d |e n t a t |i o n', WrappingIndent.DeepIndent);
assert.equal(mapper.getWrappedLinesIndent(), ' \t\t');
});
});
8 changes: 6 additions & 2 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2679,7 +2679,7 @@ declare namespace monaco.editor {
*/
wordWrapMinified?: boolean;
/**
* Control indentation of wrapped lines. Can be: 'none', 'same' or 'indent'.
* Control indentation of wrapped lines. Can be: 'none', 'same', 'indent' or 'deepIndent'.
* Defaults to 'same' in vscode and to 'none' in monaco-editor.
*/
wrappingIndent?: string;
Expand Down Expand Up @@ -2977,9 +2977,13 @@ declare namespace monaco.editor {
*/
Same = 1,
/**
* Indent => wrapped lines get +1 indentation as the parent.
* Indent => wrapped lines get +1 indentation toward the parent.
*/
Indent = 2,
/**
* DeepIndent => wrapped lines get +2 indentation toward the parent.
*/
DeepIndent = 3,
}

/**
Expand Down