提交 bf38abad 编写于 作者: H h-h-h-h

Edited the "editor.wrappingIndent" preference to allow the value "deepIndent".

The preference value "indent" adds 1 tab to the indentation of continuation lines, additionally to the indentation of the line of text in memory. "deepIndent" adds 2 tabs.
上级 4eaf5834
......@@ -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',
......
......@@ -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;
......@@ -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
}
/**
......@@ -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;
}
......
......@@ -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 = '';
......
......@@ -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[] = [];
......@@ -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;
......@@ -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');
});
});
......@@ -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;
......@@ -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,
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册