未验证 提交 b7f98568 编写于 作者: A Alexandru Dima 提交者: GitHub

Convert editor.autoIndent to 'none' | 'keep' | 'brackets' | 'a… (#85727)

Convert editor.autoIndent to 'none' | 'keep' | 'brackets' | 'advanced' | 'full' 
......@@ -40,8 +40,8 @@
"[yaml]": {
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.autoIndent": false
"editor.autoIndent": "advanced"
}
}
}
}
\ No newline at end of file
}
......@@ -11,6 +11,7 @@ import { Selection, SelectionDirection } from 'vs/editor/common/core/selection';
import { ICommand, ICursorStateComputerData, IEditOperationBuilder } from 'vs/editor/common/editorCommon';
import { ITextModel } from 'vs/editor/common/model';
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
import { EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions';
export interface IShiftCommandOpts {
isUnshift: boolean;
......@@ -18,6 +19,7 @@ export interface IShiftCommandOpts {
indentSize: number;
insertSpaces: boolean;
useTabStops: boolean;
autoIndent: EditorAutoIndentStrategy;
}
const repeatCache: { [str: string]: string[]; } = Object.create(null);
......@@ -137,7 +139,7 @@ export class ShiftCommand implements ICommand {
// The current line is "miss-aligned", so let's see if this is expected...
// This can only happen when it has trailing commas in the indent
if (model.isCheapToTokenize(lineNumber - 1)) {
let enterAction = LanguageConfigurationRegistry.getRawEnterActionAtPosition(model, lineNumber - 1, model.getLineMaxColumn(lineNumber - 1));
let enterAction = LanguageConfigurationRegistry.getRawEnterActionAtPosition(this._opts.autoIndent, model, lineNumber - 1, model.getLineMaxColumn(lineNumber - 1));
if (enterAction) {
extraSpaces = previousLineExtraSpaces;
if (enterAction.appendText) {
......
......@@ -256,6 +256,13 @@ function migrateOptions(options: IEditorOptions): void {
enabled: false
};
}
const autoIndent = options.autoIndent;
if (<any>autoIndent === true) {
options.autoIndent = 'full';
} else if (<any>autoIndent === false) {
options.autoIndent = 'advanced';
}
}
function deepCloneAndMigrateOptions(_options: IEditorOptions): IEditorOptions {
......
......@@ -31,6 +31,18 @@ export type EditorAutoSurroundStrategy = 'languageDefined' | 'quotes' | 'bracket
*/
export type EditorAutoClosingOvertypeStrategy = 'always' | 'auto' | 'never';
/**
* Configuration options for auto indentation in the editor
* @internal
*/
export const enum EditorAutoIndentStrategy {
None = 0,
Keep = 1,
Brackets = 2,
Advanced = 3,
Full = 4
}
/**
* Configuration options for the editor.
*/
......@@ -364,7 +376,7 @@ export interface IEditorOptions {
* Enable auto indentation adjustment.
* Defaults to false.
*/
autoIndent?: boolean;
autoIndent?: 'none' | 'keep' | 'brackets' | 'advanced' | 'full';
/**
* Enable format on type.
* Defaults to false.
......@@ -915,6 +927,20 @@ class EditorEnumOption<K1 extends EditorOption, T extends string, V> extends Bas
//#endregion
//#region autoIndent
function _autoIndentFromString(autoIndent: 'none' | 'keep' | 'brackets' | 'advanced' | 'full'): EditorAutoIndentStrategy {
switch (autoIndent) {
case 'none': return EditorAutoIndentStrategy.None;
case 'keep': return EditorAutoIndentStrategy.Keep;
case 'brackets': return EditorAutoIndentStrategy.Brackets;
case 'advanced': return EditorAutoIndentStrategy.Advanced;
case 'full': return EditorAutoIndentStrategy.Full;
}
}
//#endregion
//#region accessibilitySupport
class EditorAccessibilitySupport extends BaseEditorOption<EditorOption.accessibilitySupport, AccessibilitySupport> {
......@@ -3146,9 +3172,21 @@ export const EditorOptions = {
description: nls.localize('autoClosingQuotes', "Controls whether the editor should automatically close quotes after the user adds an opening quote.")
}
)),
autoIndent: register(new EditorBooleanOption(
EditorOption.autoIndent, 'autoIndent', true,
{ description: nls.localize('autoIndent', "Controls whether the editor should automatically adjust the indentation when users type, paste or move lines. Extensions with indentation rules of the language must be available.") }
autoIndent: register(new EditorEnumOption(
EditorOption.autoIndent, 'autoIndent',
EditorAutoIndentStrategy.Full, 'full',
['none', 'keep', 'brackets', 'advanced', 'full'],
_autoIndentFromString,
{
enumDescriptions: [
nls.localize('editor.autoIndent.none', "The editor will not insert indentation automatically."),
nls.localize('editor.autoIndent.keep', "The editor will keep the current line's indentation."),
nls.localize('editor.autoIndent.brackets', "The editor will keep the current line's indentation and honor language defined brackets."),
nls.localize('editor.autoIndent.advanced', "The editor will keep the current line's indentation, honor language defined brackets and invoke special onEnterRules defined by languages."),
nls.localize('editor.autoIndent.full', "The editor will keep the current line's indentation, honor language defined brackets, invoke special onEnterRules defined by languages, and honor indentationRules defined by languages."),
],
description: nls.localize('autoIndent', "Controls whether the editor should automatically adjust the indentation when users type, paste, move or indent lines.")
}
)),
automaticLayout: register(new EditorBooleanOption(
EditorOption.automaticLayout, 'automaticLayout', false,
......
......@@ -6,7 +6,7 @@
import { CharCode } from 'vs/base/common/charCode';
import { onUnexpectedError } from 'vs/base/common/errors';
import * as strings from 'vs/base/common/strings';
import { EditorAutoClosingStrategy, EditorAutoSurroundStrategy, ConfigurationChangedEvent, EditorAutoClosingOvertypeStrategy, EditorOption } from 'vs/editor/common/config/editorOptions';
import { EditorAutoClosingStrategy, EditorAutoSurroundStrategy, ConfigurationChangedEvent, EditorAutoClosingOvertypeStrategy, EditorOption, EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions';
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
......@@ -103,7 +103,7 @@ export class CursorConfiguration {
public readonly autoClosingQuotes: EditorAutoClosingStrategy;
public readonly autoClosingOvertype: EditorAutoClosingOvertypeStrategy;
public readonly autoSurround: EditorAutoSurroundStrategy;
public readonly autoIndent: boolean;
public readonly autoIndent: EditorAutoIndentStrategy;
public readonly autoClosingPairsOpen2: Map<string, StandardAutoClosingPairConditional[]>;
public readonly autoClosingPairsClose2: Map<string, StandardAutoClosingPairConditional[]>;
public readonly surroundingPairs: CharacterMap;
......
......@@ -19,6 +19,7 @@ import { ITextModel } from 'vs/editor/common/model';
import { EnterAction, IndentAction, StandardAutoClosingPairConditional } from 'vs/editor/common/modes/languageConfiguration';
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
import { IElectricAction } from 'vs/editor/common/modes/supports/electricCharacter';
import { EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions';
export class TypeOperations {
......@@ -34,7 +35,8 @@ export class TypeOperations {
tabSize: config.tabSize,
indentSize: config.indentSize,
insertSpaces: config.insertSpaces,
useTabStops: config.useTabStops
useTabStops: config.useTabStops,
autoIndent: config.autoIndent
});
}
return commands;
......@@ -48,7 +50,8 @@ export class TypeOperations {
tabSize: config.tabSize,
indentSize: config.indentSize,
insertSpaces: config.insertSpaces,
useTabStops: config.useTabStops
useTabStops: config.useTabStops,
autoIndent: config.autoIndent
});
}
return commands;
......@@ -149,15 +152,15 @@ export class TypeOperations {
let action: IndentAction | EnterAction | null = null;
let indentation: string = '';
let expectedIndentAction = config.autoIndent ? LanguageConfigurationRegistry.getInheritIndentForLine(model, lineNumber, false) : null;
const expectedIndentAction = LanguageConfigurationRegistry.getInheritIndentForLine(config.autoIndent, model, lineNumber, false);
if (expectedIndentAction) {
action = expectedIndentAction.action;
indentation = expectedIndentAction.indentation;
} else if (lineNumber > 1) {
let lastLineNumber: number;
for (lastLineNumber = lineNumber - 1; lastLineNumber >= 1; lastLineNumber--) {
let lineText = model.getLineContent(lastLineNumber);
let nonWhitespaceIdx = strings.lastNonWhitespaceIndex(lineText);
const lineText = model.getLineContent(lastLineNumber);
const nonWhitespaceIdx = strings.lastNonWhitespaceIndex(lineText);
if (nonWhitespaceIdx >= 0) {
break;
}
......@@ -168,8 +171,8 @@ export class TypeOperations {
return null;
}
let maxColumn = model.getLineMaxColumn(lastLineNumber);
let expectedEnterAction = LanguageConfigurationRegistry.getEnterAction(model, new Range(lastLineNumber, maxColumn, lastLineNumber, maxColumn));
const maxColumn = model.getLineMaxColumn(lastLineNumber);
const expectedEnterAction = LanguageConfigurationRegistry.getEnterAction(config.autoIndent, model, new Range(lastLineNumber, maxColumn, lastLineNumber, maxColumn));
if (expectedEnterAction) {
indentation = expectedEnterAction.indentation;
action = expectedEnterAction.enterAction;
......@@ -251,7 +254,8 @@ export class TypeOperations {
tabSize: config.tabSize,
indentSize: config.indentSize,
insertSpaces: config.insertSpaces,
useTabStops: config.useTabStops
useTabStops: config.useTabStops,
autoIndent: config.autoIndent
});
}
}
......@@ -289,16 +293,19 @@ export class TypeOperations {
}
private static _enter(config: CursorConfiguration, model: ITextModel, keepPosition: boolean, range: Range): ICommand {
if (!model.isCheapToTokenize(range.getStartPosition().lineNumber)) {
if (config.autoIndent === EditorAutoIndentStrategy.None) {
return TypeOperations._typeCommand(range, '\n', keepPosition);
}
if (!model.isCheapToTokenize(range.getStartPosition().lineNumber) || config.autoIndent === EditorAutoIndentStrategy.Keep) {
let lineText = model.getLineContent(range.startLineNumber);
let indentation = strings.getLeadingWhitespace(lineText).substring(0, range.startColumn - 1);
return TypeOperations._typeCommand(range, '\n' + config.normalizeIndentation(indentation), keepPosition);
}
let r = LanguageConfigurationRegistry.getEnterAction(model, range);
const r = LanguageConfigurationRegistry.getEnterAction(config.autoIndent, model, range);
if (r) {
let enterAction = r.enterAction;
let indentation = r.indentation;
const enterAction = r.enterAction;
const indentation = r.indentation;
if (enterAction.indentAction === IndentAction.None) {
// Nothing special
......@@ -310,10 +317,10 @@ export class TypeOperations {
} else if (enterAction.indentAction === IndentAction.IndentOutdent) {
// Ultra special
let normalIndent = config.normalizeIndentation(indentation);
let increasedIndent = config.normalizeIndentation(indentation + enterAction.appendText);
const normalIndent = config.normalizeIndentation(indentation);
const increasedIndent = config.normalizeIndentation(indentation + enterAction.appendText);
let typeText = '\n' + increasedIndent + '\n' + normalIndent;
const typeText = '\n' + increasedIndent + '\n' + normalIndent;
if (keepPosition) {
return new ReplaceCommandWithoutChangingPosition(range, typeText, true);
......@@ -321,72 +328,65 @@ export class TypeOperations {
return new ReplaceCommandWithOffsetCursorState(range, typeText, -1, increasedIndent.length - normalIndent.length, true);
}
} else if (enterAction.indentAction === IndentAction.Outdent) {
let actualIndentation = TypeOperations.unshiftIndent(config, indentation);
const actualIndentation = TypeOperations.unshiftIndent(config, indentation);
return TypeOperations._typeCommand(range, '\n' + config.normalizeIndentation(actualIndentation + enterAction.appendText), keepPosition);
}
}
// no enter rules applied, we should check indentation rules then.
if (!config.autoIndent) {
// Nothing special
let lineText = model.getLineContent(range.startLineNumber);
let indentation = strings.getLeadingWhitespace(lineText).substring(0, range.startColumn - 1);
return TypeOperations._typeCommand(range, '\n' + config.normalizeIndentation(indentation), keepPosition);
}
let ir = LanguageConfigurationRegistry.getIndentForEnter(model, range, {
unshiftIndent: (indent) => {
return TypeOperations.unshiftIndent(config, indent);
},
shiftIndent: (indent) => {
return TypeOperations.shiftIndent(config, indent);
},
normalizeIndentation: (indent) => {
return config.normalizeIndentation(indent);
}
}, config.autoIndent);
const lineText = model.getLineContent(range.startLineNumber);
const indentation = strings.getLeadingWhitespace(lineText).substring(0, range.startColumn - 1);
let lineText = model.getLineContent(range.startLineNumber);
let indentation = strings.getLeadingWhitespace(lineText).substring(0, range.startColumn - 1);
if (config.autoIndent >= EditorAutoIndentStrategy.Full) {
const ir = LanguageConfigurationRegistry.getIndentForEnter(config.autoIndent, model, range, {
unshiftIndent: (indent) => {
return TypeOperations.unshiftIndent(config, indent);
},
shiftIndent: (indent) => {
return TypeOperations.shiftIndent(config, indent);
},
normalizeIndentation: (indent) => {
return config.normalizeIndentation(indent);
}
});
if (ir) {
let oldEndViewColumn = CursorColumns.visibleColumnFromColumn2(config, model, range.getEndPosition());
let oldEndColumn = range.endColumn;
if (ir) {
let oldEndViewColumn = CursorColumns.visibleColumnFromColumn2(config, model, range.getEndPosition());
const oldEndColumn = range.endColumn;
let beforeText = '\n';
if (indentation !== config.normalizeIndentation(ir.beforeEnter)) {
beforeText = config.normalizeIndentation(ir.beforeEnter) + lineText.substring(indentation.length, range.startColumn - 1) + '\n';
range = new Range(range.startLineNumber, 1, range.endLineNumber, range.endColumn);
}
let beforeText = '\n';
if (indentation !== config.normalizeIndentation(ir.beforeEnter)) {
beforeText = config.normalizeIndentation(ir.beforeEnter) + lineText.substring(indentation.length, range.startColumn - 1) + '\n';
range = new Range(range.startLineNumber, 1, range.endLineNumber, range.endColumn);
}
let newLineContent = model.getLineContent(range.endLineNumber);
let firstNonWhitespace = strings.firstNonWhitespaceIndex(newLineContent);
if (firstNonWhitespace >= 0) {
range = range.setEndPosition(range.endLineNumber, Math.max(range.endColumn, firstNonWhitespace + 1));
} else {
range = range.setEndPosition(range.endLineNumber, model.getLineMaxColumn(range.endLineNumber));
}
const newLineContent = model.getLineContent(range.endLineNumber);
const firstNonWhitespace = strings.firstNonWhitespaceIndex(newLineContent);
if (firstNonWhitespace >= 0) {
range = range.setEndPosition(range.endLineNumber, Math.max(range.endColumn, firstNonWhitespace + 1));
} else {
range = range.setEndPosition(range.endLineNumber, model.getLineMaxColumn(range.endLineNumber));
}
if (keepPosition) {
return new ReplaceCommandWithoutChangingPosition(range, beforeText + config.normalizeIndentation(ir.afterEnter), true);
} else {
let offset = 0;
if (oldEndColumn <= firstNonWhitespace + 1) {
if (!config.insertSpaces) {
oldEndViewColumn = Math.ceil(oldEndViewColumn / config.indentSize);
if (keepPosition) {
return new ReplaceCommandWithoutChangingPosition(range, beforeText + config.normalizeIndentation(ir.afterEnter), true);
} else {
let offset = 0;
if (oldEndColumn <= firstNonWhitespace + 1) {
if (!config.insertSpaces) {
oldEndViewColumn = Math.ceil(oldEndViewColumn / config.indentSize);
}
offset = Math.min(oldEndViewColumn + 1 - config.normalizeIndentation(ir.afterEnter).length - 1, 0);
}
offset = Math.min(oldEndViewColumn + 1 - config.normalizeIndentation(ir.afterEnter).length - 1, 0);
return new ReplaceCommandWithOffsetCursorState(range, beforeText + config.normalizeIndentation(ir.afterEnter), 0, offset, true);
}
return new ReplaceCommandWithOffsetCursorState(range, beforeText + config.normalizeIndentation(ir.afterEnter), 0, offset, true);
}
} else {
return TypeOperations._typeCommand(range, '\n' + config.normalizeIndentation(indentation), keepPosition);
}
return TypeOperations._typeCommand(range, '\n' + config.normalizeIndentation(indentation), keepPosition);
}
private static _isAutoIndentType(config: CursorConfiguration, model: ITextModel, selections: Selection[]): boolean {
if (!config.autoIndent) {
if (config.autoIndent < EditorAutoIndentStrategy.Full) {
return false;
}
......@@ -400,8 +400,8 @@ export class TypeOperations {
}
private static _runAutoIndentType(config: CursorConfiguration, model: ITextModel, range: Range, ch: string): ICommand | null {
let currentIndentation = LanguageConfigurationRegistry.getIndentationAtPosition(model, range.startLineNumber, range.startColumn);
let actualIndentation = LanguageConfigurationRegistry.getIndentActionForType(model, range, ch, {
const currentIndentation = LanguageConfigurationRegistry.getIndentationAtPosition(model, range.startLineNumber, range.startColumn);
const actualIndentation = LanguageConfigurationRegistry.getIndentActionForType(config.autoIndent, model, range, ch, {
shiftIndent: (indentation) => {
return TypeOperations.shiftIndent(config, indentation);
},
......@@ -415,7 +415,7 @@ export class TypeOperations {
}
if (actualIndentation !== config.normalizeIndentation(currentIndentation)) {
let firstNonWhitespace = model.getLineFirstNonWhitespaceColumn(range.startLineNumber);
const firstNonWhitespace = model.getLineFirstNonWhitespaceColumn(range.startLineNumber);
if (firstNonWhitespace === 0) {
return TypeOperations._typeCommand(
new Range(range.startLineNumber, 0, range.endLineNumber, range.endColumn),
......
......@@ -13,12 +13,13 @@ import { ITextModel } from 'vs/editor/common/model';
import { DEFAULT_WORD_REGEXP, ensureValidWordDefinition } from 'vs/editor/common/model/wordHelper';
import { LanguageId, LanguageIdentifier } from 'vs/editor/common/modes';
import { EnterAction, FoldingRules, IAutoClosingPair, IndentAction, IndentationRule, LanguageConfiguration, StandardAutoClosingPairConditional } from 'vs/editor/common/modes/languageConfiguration';
import { createScopedLineTokens } from 'vs/editor/common/modes/supports';
import { createScopedLineTokens, ScopedLineTokens } from 'vs/editor/common/modes/supports';
import { CharacterPairSupport } from 'vs/editor/common/modes/supports/characterPair';
import { BracketElectricCharacterSupport, IElectricAction } from 'vs/editor/common/modes/supports/electricCharacter';
import { IndentConsts, IndentRulesSupport } from 'vs/editor/common/modes/supports/indentRules';
import { IOnEnterSupportOptions, OnEnterSupport } from 'vs/editor/common/modes/supports/onEnter';
import { RichEditBrackets } from 'vs/editor/common/modes/supports/richEditBrackets';
import { EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions';
/**
* Interface used to support insertion of mode specific comments.
......@@ -351,8 +352,12 @@ export class LanguageConfigurationRegistryImpl {
*
* This function only return the inherited indent based on above lines, it doesn't check whether current line should decrease or not.
*/
public getInheritIndentForLine(model: IVirtualModel, lineNumber: number, honorIntentialIndent: boolean = true): { indentation: string; action: IndentAction | null; line?: number; } | null {
let indentRulesSupport = this.getIndentRulesSupport(model.getLanguageIdentifier().id);
public getInheritIndentForLine(autoIndent: EditorAutoIndentStrategy, model: IVirtualModel, lineNumber: number, honorIntentialIndent: boolean = true): { indentation: string; action: IndentAction | null; line?: number; } | null {
if (autoIndent < EditorAutoIndentStrategy.Full) {
return null;
}
const indentRulesSupport = this.getIndentRulesSupport(model.getLanguageIdentifier().id);
if (!indentRulesSupport) {
return null;
}
......@@ -364,7 +369,7 @@ export class LanguageConfigurationRegistryImpl {
};
}
let precedingUnIgnoredLine = this.getPrecedingValidLine(model, lineNumber, indentRulesSupport);
const precedingUnIgnoredLine = this.getPrecedingValidLine(model, lineNumber, indentRulesSupport);
if (precedingUnIgnoredLine < 0) {
return null;
} else if (precedingUnIgnoredLine < 1) {
......@@ -374,8 +379,7 @@ export class LanguageConfigurationRegistryImpl {
};
}
let precedingUnIgnoredLineContent = model.getLineContent(precedingUnIgnoredLine);
const precedingUnIgnoredLineContent = model.getLineContent(precedingUnIgnoredLine);
if (indentRulesSupport.shouldIncrease(precedingUnIgnoredLineContent) || indentRulesSupport.shouldIndentNextLine(precedingUnIgnoredLineContent)) {
return {
indentation: strings.getLeadingWhitespace(precedingUnIgnoredLineContent),
......@@ -402,9 +406,9 @@ export class LanguageConfigurationRegistryImpl {
};
}
let previousLine = precedingUnIgnoredLine - 1;
const previousLine = precedingUnIgnoredLine - 1;
let previousLineIndentMetadata = indentRulesSupport.getIndentMetadata(model.getLineContent(previousLine));
const previousLineIndentMetadata = indentRulesSupport.getIndentMetadata(model.getLineContent(previousLine));
if (!(previousLineIndentMetadata & (IndentConsts.INCREASE_MASK | IndentConsts.DECREASE_MASK)) &&
(previousLineIndentMetadata & IndentConsts.INDENT_NEXTLINE_MASK)) {
let stopLine = 0;
......@@ -432,7 +436,7 @@ export class LanguageConfigurationRegistryImpl {
} else {
// search from precedingUnIgnoredLine until we find one whose indent is not temporary
for (let i = precedingUnIgnoredLine; i > 0; i--) {
let lineContent = model.getLineContent(i);
const lineContent = model.getLineContent(i);
if (indentRulesSupport.shouldIncrease(lineContent)) {
return {
indentation: strings.getLeadingWhitespace(lineContent),
......@@ -472,23 +476,27 @@ export class LanguageConfigurationRegistryImpl {
}
}
public getGoodIndentForLine(virtualModel: IVirtualModel, languageId: LanguageId, lineNumber: number, indentConverter: IIndentConverter): string | null {
let indentRulesSupport = this.getIndentRulesSupport(languageId);
public getGoodIndentForLine(autoIndent: EditorAutoIndentStrategy, virtualModel: IVirtualModel, languageId: LanguageId, lineNumber: number, indentConverter: IIndentConverter): string | null {
if (autoIndent < EditorAutoIndentStrategy.Full) {
return null;
}
const indentRulesSupport = this.getIndentRulesSupport(languageId);
if (!indentRulesSupport) {
return null;
}
let indent = this.getInheritIndentForLine(virtualModel, lineNumber);
let lineContent = virtualModel.getLineContent(lineNumber);
const indent = this.getInheritIndentForLine(autoIndent, virtualModel, lineNumber);
const lineContent = virtualModel.getLineContent(lineNumber);
if (indent) {
let inheritLine = indent.line;
const inheritLine = indent.line;
if (inheritLine !== undefined) {
let onEnterSupport = this._getOnEnterSupport(languageId);
const onEnterSupport = this._getOnEnterSupport(languageId);
let enterResult: EnterAction | null = null;
try {
if (onEnterSupport) {
enterResult = onEnterSupport.onEnter('', virtualModel.getLineContent(inheritLine), '');
enterResult = onEnterSupport.onEnter(autoIndent, '', virtualModel.getLineContent(inheritLine), '');
}
} catch (e) {
onUnexpectedError(e);
......@@ -539,16 +547,17 @@ export class LanguageConfigurationRegistryImpl {
return null;
}
public getIndentForEnter(model: ITextModel, range: Range, indentConverter: IIndentConverter, autoIndent: boolean): { beforeEnter: string, afterEnter: string } | null {
public getIndentForEnter(autoIndent: EditorAutoIndentStrategy, model: ITextModel, range: Range, indentConverter: IIndentConverter): { beforeEnter: string, afterEnter: string } | null {
if (autoIndent < EditorAutoIndentStrategy.Full) {
return null;
}
model.forceTokenization(range.startLineNumber);
let lineTokens = model.getLineTokens(range.startLineNumber);
let beforeEnterText;
let afterEnterText;
let scopedLineTokens = createScopedLineTokens(lineTokens, range.startColumn - 1);
let scopedLineText = scopedLineTokens.getLineContent();
const lineTokens = model.getLineTokens(range.startLineNumber);
const scopedLineTokens = createScopedLineTokens(lineTokens, range.startColumn - 1);
const scopedLineText = scopedLineTokens.getLineContent();
let embeddedLanguage = false;
let beforeEnterText: string;
if (scopedLineTokens.firstCharOffset > 0 && lineTokens.getLanguageId(0) !== scopedLineTokens.languageId) {
// we are in the embeded language content
embeddedLanguage = true; // if embeddedLanguage is true, then we don't touch the indentation of current line
......@@ -557,6 +566,7 @@ export class LanguageConfigurationRegistryImpl {
beforeEnterText = lineTokens.getLineContent().substring(0, range.startColumn - 1);
}
let afterEnterText: string;
if (range.isEmpty()) {
afterEnterText = scopedLineText.substr(range.startColumn - 1 - scopedLineTokens.firstCharOffset);
} else {
......@@ -564,31 +574,15 @@ export class LanguageConfigurationRegistryImpl {
afterEnterText = endScopedLineTokens.getLineContent().substr(range.endColumn - 1 - scopedLineTokens.firstCharOffset);
}
let indentRulesSupport = this.getIndentRulesSupport(scopedLineTokens.languageId);
const indentRulesSupport = this.getIndentRulesSupport(scopedLineTokens.languageId);
if (!indentRulesSupport) {
return null;
}
let beforeEnterResult = beforeEnterText;
let beforeEnterIndent = strings.getLeadingWhitespace(beforeEnterText);
if (!autoIndent && !embeddedLanguage) {
let beforeEnterIndentAction = this.getInheritIndentForLine(model, range.startLineNumber);
if (indentRulesSupport.shouldDecrease(beforeEnterText)) {
if (beforeEnterIndentAction) {
beforeEnterIndent = beforeEnterIndentAction.indentation;
if (beforeEnterIndentAction.action !== IndentAction.Indent) {
beforeEnterIndent = indentConverter.unshiftIndent(beforeEnterIndent);
}
}
}
const beforeEnterResult = beforeEnterText;
const beforeEnterIndent = strings.getLeadingWhitespace(beforeEnterText);
beforeEnterResult = beforeEnterIndent + strings.ltrim(strings.ltrim(beforeEnterText, ' '), '\t');
}
let virtualModel: IVirtualModel = {
const virtualModel: IVirtualModel = {
getLineTokens: (lineNumber: number) => {
return model.getLineTokens(lineNumber);
},
......@@ -607,10 +601,10 @@ export class LanguageConfigurationRegistryImpl {
}
};
let currentLineIndent = strings.getLeadingWhitespace(lineTokens.getLineContent());
let afterEnterAction = this.getInheritIndentForLine(virtualModel, range.startLineNumber + 1);
const currentLineIndent = strings.getLeadingWhitespace(lineTokens.getLineContent());
const afterEnterAction = this.getInheritIndentForLine(autoIndent, virtualModel, range.startLineNumber + 1);
if (!afterEnterAction) {
let beforeEnter = embeddedLanguage ? currentLineIndent : beforeEnterIndent;
const beforeEnter = embeddedLanguage ? currentLineIndent : beforeEnterIndent;
return {
beforeEnter: beforeEnter,
afterEnter: beforeEnter
......@@ -637,18 +631,21 @@ export class LanguageConfigurationRegistryImpl {
* We should always allow intentional indentation. It means, if users change the indentation of `lineNumber` and the content of
* this line doesn't match decreaseIndentPattern, we should not adjust the indentation.
*/
public getIndentActionForType(model: ITextModel, range: Range, ch: string, indentConverter: IIndentConverter): string | null {
let scopedLineTokens = this.getScopedLineTokens(model, range.startLineNumber, range.startColumn);
let indentRulesSupport = this.getIndentRulesSupport(scopedLineTokens.languageId);
public getIndentActionForType(autoIndent: EditorAutoIndentStrategy, model: ITextModel, range: Range, ch: string, indentConverter: IIndentConverter): string | null {
if (autoIndent < EditorAutoIndentStrategy.Full) {
return null;
}
const scopedLineTokens = this.getScopedLineTokens(model, range.startLineNumber, range.startColumn);
const indentRulesSupport = this.getIndentRulesSupport(scopedLineTokens.languageId);
if (!indentRulesSupport) {
return null;
}
let scopedLineText = scopedLineTokens.getLineContent();
let beforeTypeText = scopedLineText.substr(0, range.startColumn - 1 - scopedLineTokens.firstCharOffset);
let afterTypeText;
const scopedLineText = scopedLineTokens.getLineContent();
const beforeTypeText = scopedLineText.substr(0, range.startColumn - 1 - scopedLineTokens.firstCharOffset);
// selection support
let afterTypeText: string;
if (range.isEmpty()) {
afterTypeText = scopedLineText.substr(range.startColumn - 1 - scopedLineTokens.firstCharOffset);
} else {
......@@ -661,13 +658,12 @@ export class LanguageConfigurationRegistryImpl {
if (!indentRulesSupport.shouldDecrease(beforeTypeText + afterTypeText) && indentRulesSupport.shouldDecrease(beforeTypeText + ch + afterTypeText)) {
// after typing `ch`, the content matches decreaseIndentPattern, we should adjust the indent to a good manner.
// 1. Get inherited indent action
let r = this.getInheritIndentForLine(model, range.startLineNumber, false);
const r = this.getInheritIndentForLine(autoIndent, model, range.startLineNumber, false);
if (!r) {
return null;
}
let indentation = r.indentation;
if (r.action !== IndentAction.Indent) {
indentation = indentConverter.unshiftIndent(indentation);
}
......@@ -679,15 +675,13 @@ export class LanguageConfigurationRegistryImpl {
}
public getIndentMetadata(model: ITextModel, lineNumber: number): number | null {
let indentRulesSupport = this.getIndentRulesSupport(model.getLanguageIdentifier().id);
const indentRulesSupport = this.getIndentRulesSupport(model.getLanguageIdentifier().id);
if (!indentRulesSupport) {
return null;
}
if (lineNumber < 1 || lineNumber > model.getLineCount()) {
return null;
}
return indentRulesSupport.getIndentMetadata(model.getLineContent(lineNumber));
}
......@@ -696,33 +690,30 @@ export class LanguageConfigurationRegistryImpl {
// begin onEnter
private _getOnEnterSupport(languageId: LanguageId): OnEnterSupport | null {
let value = this._getRichEditSupport(languageId);
const value = this._getRichEditSupport(languageId);
if (!value) {
return null;
}
return value.onEnter || null;
}
public getRawEnterActionAtPosition(model: ITextModel, lineNumber: number, column: number): EnterAction | null {
let r = this.getEnterAction(model, new Range(lineNumber, column, lineNumber, column));
public getRawEnterActionAtPosition(autoIndent: EditorAutoIndentStrategy, model: ITextModel, lineNumber: number, column: number): EnterAction | null {
const r = this.getEnterAction(autoIndent, model, new Range(lineNumber, column, lineNumber, column));
return r ? r.enterAction : null;
}
public getEnterAction(model: ITextModel, range: Range): { enterAction: EnterAction; indentation: string; } | null {
let indentation = this.getIndentationAtPosition(model, range.startLineNumber, range.startColumn);
let scopedLineTokens = this.getScopedLineTokens(model, range.startLineNumber, range.startColumn);
let onEnterSupport = this._getOnEnterSupport(scopedLineTokens.languageId);
public getEnterAction(autoIndent: EditorAutoIndentStrategy, model: ITextModel, range: Range): { enterAction: EnterAction; indentation: string; } | null {
const scopedLineTokens = this.getScopedLineTokens(model, range.startLineNumber, range.startColumn);
const onEnterSupport = this._getOnEnterSupport(scopedLineTokens.languageId);
if (!onEnterSupport) {
return null;
}
let scopedLineText = scopedLineTokens.getLineContent();
let beforeEnterText = scopedLineText.substr(0, range.startColumn - 1 - scopedLineTokens.firstCharOffset);
let afterEnterText;
const scopedLineText = scopedLineTokens.getLineContent();
const beforeEnterText = scopedLineText.substr(0, range.startColumn - 1 - scopedLineTokens.firstCharOffset);
// selection support
let afterEnterText: string;
if (range.isEmpty()) {
afterEnterText = scopedLineText.substr(range.startColumn - 1 - scopedLineTokens.firstCharOffset);
} else {
......@@ -730,12 +721,10 @@ export class LanguageConfigurationRegistryImpl {
afterEnterText = endScopedLineTokens.getLineContent().substr(range.endColumn - 1 - scopedLineTokens.firstCharOffset);
}
let lineNumber = range.startLineNumber;
let oneLineAboveText = '';
if (lineNumber > 1 && scopedLineTokens.firstCharOffset === 0) {
if (range.startLineNumber > 1 && scopedLineTokens.firstCharOffset === 0) {
// This is not the first line and the entire line belongs to this mode
let oneLineAboveScopedLineTokens = this.getScopedLineTokens(model, lineNumber - 1);
const oneLineAboveScopedLineTokens = this.getScopedLineTokens(model, range.startLineNumber - 1);
if (oneLineAboveScopedLineTokens.languageId === scopedLineTokens.languageId) {
// The line above ends with text belonging to the same mode
oneLineAboveText = oneLineAboveScopedLineTokens.getLineContent();
......@@ -744,7 +733,7 @@ export class LanguageConfigurationRegistryImpl {
let enterResult: EnterAction | null = null;
try {
enterResult = onEnterSupport.onEnter(oneLineAboveText, beforeEnterText, afterEnterText);
enterResult = onEnterSupport.onEnter(autoIndent, oneLineAboveText, beforeEnterText, afterEnterText);
} catch (e) {
onUnexpectedError(e);
}
......@@ -765,6 +754,7 @@ export class LanguageConfigurationRegistryImpl {
}
}
let indentation = this.getIndentationAtPosition(model, range.startLineNumber, range.startColumn);
if (enterResult.removeText) {
indentation = indentation.substring(0, indentation.length - enterResult.removeText);
}
......@@ -776,27 +766,25 @@ export class LanguageConfigurationRegistryImpl {
}
public getIndentationAtPosition(model: ITextModel, lineNumber: number, column: number): string {
let lineText = model.getLineContent(lineNumber);
const lineText = model.getLineContent(lineNumber);
let indentation = strings.getLeadingWhitespace(lineText);
if (indentation.length > column - 1) {
indentation = indentation.substring(0, column - 1);
}
return indentation;
}
private getScopedLineTokens(model: ITextModel, lineNumber: number, columnNumber?: number) {
private getScopedLineTokens(model: ITextModel, lineNumber: number, columnNumber?: number): ScopedLineTokens {
model.forceTokenization(lineNumber);
let lineTokens = model.getLineTokens(lineNumber);
let column = (typeof columnNumber === 'undefined' ? model.getLineMaxColumn(lineNumber) - 1 : columnNumber - 1);
let scopedLineTokens = createScopedLineTokens(lineTokens, column);
return scopedLineTokens;
const lineTokens = model.getLineTokens(lineNumber);
const column = (typeof columnNumber === 'undefined' ? model.getLineMaxColumn(lineNumber) - 1 : columnNumber - 1);
return createScopedLineTokens(lineTokens, column);
}
// end onEnter
public getBracketsSupport(languageId: LanguageId): RichEditBrackets | null {
let value = this._getRichEditSupport(languageId);
const value = this._getRichEditSupport(languageId);
if (!value) {
return null;
}
......
......@@ -6,6 +6,7 @@
import { onUnexpectedError } from 'vs/base/common/errors';
import * as strings from 'vs/base/common/strings';
import { CharacterPair, EnterAction, IndentAction, OnEnterRule } from 'vs/editor/common/modes/languageConfiguration';
import { EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions';
export interface IOnEnterSupportOptions {
brackets?: CharacterPair[];
......@@ -48,46 +49,51 @@ export class OnEnterSupport {
this._regExpRules = opts.regExpRules || [];
}
public onEnter(oneLineAboveText: string, beforeEnterText: string, afterEnterText: string): EnterAction | null {
public onEnter(autoIndent: EditorAutoIndentStrategy, oneLineAboveText: string, beforeEnterText: string, afterEnterText: string): EnterAction | null {
// (1): `regExpRules`
for (let i = 0, len = this._regExpRules.length; i < len; i++) {
let rule = this._regExpRules[i];
const regResult = [{
reg: rule.beforeText,
text: beforeEnterText
}, {
reg: rule.afterText,
text: afterEnterText
}, {
reg: rule.oneLineAboveText,
text: oneLineAboveText
}].every((obj): boolean => {
return obj.reg ? obj.reg.test(obj.text) : true;
});
if (regResult) {
return rule.action;
if (autoIndent >= EditorAutoIndentStrategy.Advanced) {
for (let i = 0, len = this._regExpRules.length; i < len; i++) {
let rule = this._regExpRules[i];
const regResult = [{
reg: rule.beforeText,
text: beforeEnterText
}, {
reg: rule.afterText,
text: afterEnterText
}, {
reg: rule.oneLineAboveText,
text: oneLineAboveText
}].every((obj): boolean => {
return obj.reg ? obj.reg.test(obj.text) : true;
});
if (regResult) {
return rule.action;
}
}
}
// (2): Special indent-outdent
if (beforeEnterText.length > 0 && afterEnterText.length > 0) {
for (let i = 0, len = this._brackets.length; i < len; i++) {
let bracket = this._brackets[i];
if (bracket.openRegExp.test(beforeEnterText) && bracket.closeRegExp.test(afterEnterText)) {
return { indentAction: IndentAction.IndentOutdent };
if (autoIndent >= EditorAutoIndentStrategy.Brackets) {
if (beforeEnterText.length > 0 && afterEnterText.length > 0) {
for (let i = 0, len = this._brackets.length; i < len; i++) {
let bracket = this._brackets[i];
if (bracket.openRegExp.test(beforeEnterText) && bracket.closeRegExp.test(afterEnterText)) {
return { indentAction: IndentAction.IndentOutdent };
}
}
}
}
// (4): Open bracket based logic
if (beforeEnterText.length > 0) {
for (let i = 0, len = this._brackets.length; i < len; i++) {
let bracket = this._brackets[i];
if (bracket.openRegExp.test(beforeEnterText)) {
return { indentAction: IndentAction.Indent };
if (autoIndent >= EditorAutoIndentStrategy.Brackets) {
if (beforeEnterText.length > 0) {
for (let i = 0, len = this._brackets.length; i < len; i++) {
let bracket = this._brackets[i];
if (bracket.openRegExp.test(beforeEnterText)) {
return { indentAction: IndentAction.Indent };
}
}
}
}
......
......@@ -22,7 +22,7 @@ import { IndentConsts } from 'vs/editor/common/modes/supports/indentRules';
import { IModelService } from 'vs/editor/common/services/modelService';
import * as indentUtils from 'vs/editor/contrib/indentation/indentUtils';
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { EditorOption, EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions';
export function getReindentEditOperations(model: ITextModel, startLineNumber: number, endLineNumber: number, inheritedIndent?: string): IIdentifiedSingleEditOperation[] {
if (model.getLineCount() === 1 && model.getLineMaxColumn(1) === 1) {
......@@ -442,7 +442,7 @@ export class AutoIndentOnPaste implements IEditorContribution {
this.callOnModel.clear();
// we are disabled
if (!this.editor.getOption(EditorOption.autoIndent) || this.editor.getOption(EditorOption.formatOnPaste)) {
if (this.editor.getOption(EditorOption.autoIndent) < EditorAutoIndentStrategy.Full || this.editor.getOption(EditorOption.formatOnPaste)) {
return;
}
......@@ -470,6 +470,7 @@ export class AutoIndentOnPaste implements IEditorContribution {
if (!model.isCheapToTokenize(range.getStartPosition().lineNumber)) {
return;
}
const autoIndent = this.editor.getOption(EditorOption.autoIndent);
const { tabSize, indentSize, insertSpaces } = model.getOptions();
this.editor.pushUndoStop();
let textEdits: TextEdit[] = [];
......@@ -499,7 +500,7 @@ export class AutoIndentOnPaste implements IEditorContribution {
let firstLineText = model.getLineContent(startLineNumber);
if (!/\S/.test(firstLineText.substring(0, range.startColumn - 1))) {
let indentOfFirstLine = LanguageConfigurationRegistry.getGoodIndentForLine(model, model.getLanguageIdentifier().id, startLineNumber, indentConverter);
let indentOfFirstLine = LanguageConfigurationRegistry.getGoodIndentForLine(autoIndent, model, model.getLanguageIdentifier().id, startLineNumber, indentConverter);
if (indentOfFirstLine !== null) {
let oldIndentation = strings.getLeadingWhitespace(firstLineText);
......@@ -557,7 +558,7 @@ export class AutoIndentOnPaste implements IEditorContribution {
}
}
};
let indentOfSecondLine = LanguageConfigurationRegistry.getGoodIndentForLine(virtualModel, model.getLanguageIdentifier().id, startLineNumber + 1, indentConverter);
let indentOfSecondLine = LanguageConfigurationRegistry.getGoodIndentForLine(autoIndent, virtualModel, model.getLanguageIdentifier().id, startLineNumber + 1, indentConverter);
if (indentOfSecondLine !== null) {
let newSpaceCntOfSecondLine = indentUtils.getSpaceCnt(indentOfSecondLine, tabSize);
let oldSpaceCntOfSecondLine = indentUtils.getSpaceCnt(strings.getLeadingWhitespace(model.getLineContent(startLineNumber + 1)), tabSize);
......
......@@ -13,18 +13,19 @@ import { IndentAction } from 'vs/editor/common/modes/languageConfiguration';
import { IIndentConverter, LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
import { IndentConsts } from 'vs/editor/common/modes/supports/indentRules';
import * as indentUtils from 'vs/editor/contrib/indentation/indentUtils';
import { EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions';
export class MoveLinesCommand implements ICommand {
private readonly _selection: Selection;
private readonly _isMovingDown: boolean;
private readonly _autoIndent: boolean;
private readonly _autoIndent: EditorAutoIndentStrategy;
private _selectionId: string | null;
private _moveEndPositionDown?: boolean;
private _moveEndLineSelectionShrink: boolean;
constructor(selection: Selection, isMovingDown: boolean, autoIndent: boolean) {
constructor(selection: Selection, isMovingDown: boolean, autoIndent: EditorAutoIndentStrategy) {
this._selection = selection;
this._isMovingDown = isMovingDown;
this._autoIndent = autoIndent;
......@@ -117,7 +118,7 @@ export class MoveLinesCommand implements ICommand {
return model.getLineContent(lineNumber);
}
};
let indentOfMovingLine = LanguageConfigurationRegistry.getGoodIndentForLine(virtualModel, model.getLanguageIdAtPosition(
let indentOfMovingLine = LanguageConfigurationRegistry.getGoodIndentForLine(this._autoIndent, virtualModel, model.getLanguageIdAtPosition(
movingLineNumber, 1), s.startLineNumber, indentConverter);
if (indentOfMovingLine !== null) {
let oldIndentation = strings.getLeadingWhitespace(model.getLineContent(movingLineNumber));
......@@ -152,7 +153,7 @@ export class MoveLinesCommand implements ICommand {
}
};
let newIndentatOfMovingBlock = LanguageConfigurationRegistry.getGoodIndentForLine(virtualModel, model.getLanguageIdAtPosition(
let newIndentatOfMovingBlock = LanguageConfigurationRegistry.getGoodIndentForLine(this._autoIndent, virtualModel, model.getLanguageIdAtPosition(
movingLineNumber, 1), s.startLineNumber + 1, indentConverter);
if (newIndentatOfMovingBlock !== null) {
......@@ -197,7 +198,7 @@ export class MoveLinesCommand implements ICommand {
}
} else {
// it doesn't match any onEnter rule, let's check indentation rules then.
let indentOfFirstLine = LanguageConfigurationRegistry.getGoodIndentForLine(virtualModel, model.getLanguageIdAtPosition(s.startLineNumber, 1), movingLineNumber, indentConverter);
let indentOfFirstLine = LanguageConfigurationRegistry.getGoodIndentForLine(this._autoIndent, virtualModel, model.getLanguageIdAtPosition(s.startLineNumber, 1), movingLineNumber, indentConverter);
if (indentOfFirstLine !== null) {
// adjust the indentation of the moving block
let oldIndent = strings.getLeadingWhitespace(model.getLineContent(s.startLineNumber));
......@@ -251,7 +252,7 @@ export class MoveLinesCommand implements ICommand {
}
let maxColumn = model.getLineMaxColumn(validPrecedingLine);
let enter = LanguageConfigurationRegistry.getEnterAction(model, new Range(validPrecedingLine, maxColumn, validPrecedingLine, maxColumn));
let enter = LanguageConfigurationRegistry.getEnterAction(this._autoIndent, model, new Range(validPrecedingLine, maxColumn, validPrecedingLine, maxColumn));
if (enter) {
let enterPrefix = enter.indentation;
......@@ -288,7 +289,7 @@ export class MoveLinesCommand implements ICommand {
}
private shouldAutoIndent(model: ITextModel, selection: Selection) {
if (!this._autoIndent) {
if (this._autoIndent < EditorAutoIndentStrategy.Full) {
return false;
}
// if it's not easy to tokenize, we stop auto indent.
......
......@@ -9,21 +9,22 @@ import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageCo
import { MoveLinesCommand } from 'vs/editor/contrib/linesOperations/moveLinesCommand';
import { testCommand } from 'vs/editor/test/browser/testCommand';
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
import { EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions';
function testMoveLinesDownCommand(lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection): void {
testCommand(lines, null, selection, (sel) => new MoveLinesCommand(sel, true, false), expectedLines, expectedSelection);
testCommand(lines, null, selection, (sel) => new MoveLinesCommand(sel, true, EditorAutoIndentStrategy.Advanced), expectedLines, expectedSelection);
}
function testMoveLinesUpCommand(lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection): void {
testCommand(lines, null, selection, (sel) => new MoveLinesCommand(sel, false, false), expectedLines, expectedSelection);
testCommand(lines, null, selection, (sel) => new MoveLinesCommand(sel, false, EditorAutoIndentStrategy.Advanced), expectedLines, expectedSelection);
}
function testMoveLinesDownWithIndentCommand(languageId: LanguageIdentifier, lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection): void {
testCommand(lines, languageId, selection, (sel) => new MoveLinesCommand(sel, true, true), expectedLines, expectedSelection);
testCommand(lines, languageId, selection, (sel) => new MoveLinesCommand(sel, true, EditorAutoIndentStrategy.Full), expectedLines, expectedSelection);
}
function testMoveLinesUpWithIndentCommand(languageId: LanguageIdentifier, lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection): void {
testCommand(lines, languageId, selection, (sel) => new MoveLinesCommand(sel, false, true), expectedLines, expectedSelection);
testCommand(lines, languageId, selection, (sel) => new MoveLinesCommand(sel, false, EditorAutoIndentStrategy.Full), expectedLines, expectedSelection);
}
suite('Editor Contrib - Move Lines Command', () => {
......
......@@ -13,7 +13,7 @@ const global: any = self;
// Set defaults for standalone editor
(<any>EditorOptions.wrappingIndent).defaultValue = WrappingIndent.None;
(<any>EditorOptions.glyphMargin).defaultValue = false;
(<any>EditorOptions.autoIndent).defaultValue = false;
(<any>EditorOptions.autoIndent).defaultValue = 'advanced';
(<any>EditorOptions.overviewRulerLanes).defaultValue = 2;
const api = createMonacoBaseAPI();
......
......@@ -14,6 +14,7 @@ import { getEditOperation, testCommand } from 'vs/editor/test/browser/testComman
import { withEditorModel } from 'vs/editor/test/common/editorTestUtils';
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
import { EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions';
/**
* Create single edit operation
......@@ -50,6 +51,7 @@ function testShiftCommand(lines: string[], languageIdentifier: LanguageIdentifie
indentSize: 4,
insertSpaces: false,
useTabStops: useTabStops,
autoIndent: EditorAutoIndentStrategy.Full,
}), expectedLines, expectedSelection);
}
......@@ -60,6 +62,7 @@ function testUnshiftCommand(lines: string[], languageIdentifier: LanguageIdentif
indentSize: 4,
insertSpaces: false,
useTabStops: useTabStops,
autoIndent: EditorAutoIndentStrategy.Full,
}), expectedLines, expectedSelection);
}
......@@ -672,7 +675,8 @@ suite('Editor Commands - ShiftCommand', () => {
tabSize: 4,
indentSize: 4,
insertSpaces: true,
useTabStops: false
useTabStops: false,
autoIndent: EditorAutoIndentStrategy.Full,
}),
[
' Written | Numeric',
......@@ -717,7 +721,8 @@ suite('Editor Commands - ShiftCommand', () => {
tabSize: 4,
indentSize: 4,
insertSpaces: true,
useTabStops: false
useTabStops: false,
autoIndent: EditorAutoIndentStrategy.Full,
}),
[
' Written | Numeric',
......@@ -762,7 +767,8 @@ suite('Editor Commands - ShiftCommand', () => {
tabSize: 4,
indentSize: 4,
insertSpaces: false,
useTabStops: false
useTabStops: false,
autoIndent: EditorAutoIndentStrategy.Full,
}),
[
' Written | Numeric',
......@@ -807,7 +813,8 @@ suite('Editor Commands - ShiftCommand', () => {
tabSize: 4,
indentSize: 4,
insertSpaces: true,
useTabStops: false
useTabStops: false,
autoIndent: EditorAutoIndentStrategy.Full,
}),
[
' Written | Numeric',
......@@ -841,7 +848,8 @@ suite('Editor Commands - ShiftCommand', () => {
tabSize: 4,
indentSize: 4,
insertSpaces: false,
useTabStops: true
useTabStops: true,
autoIndent: EditorAutoIndentStrategy.Full,
}),
[
'\tHello world!',
......@@ -951,7 +959,8 @@ suite('Editor Commands - ShiftCommand', () => {
tabSize: tabSize,
indentSize: indentSize,
insertSpaces: insertSpaces,
useTabStops: true
useTabStops: true,
autoIndent: EditorAutoIndentStrategy.Full,
});
let actual = getEditOperation(model, op);
assert.deepEqual(actual, expected);
......@@ -965,7 +974,8 @@ suite('Editor Commands - ShiftCommand', () => {
tabSize: tabSize,
indentSize: indentSize,
insertSpaces: insertSpaces,
useTabStops: true
useTabStops: true,
autoIndent: EditorAutoIndentStrategy.Full,
});
let actual = getEditOperation(model, op);
assert.deepEqual(actual, expected);
......
......@@ -2834,7 +2834,7 @@ suite('Editor Controller - Indentation Rules', () => {
],
languageIdentifier: mode.getLanguageIdentifier(),
modelOpts: { insertSpaces: false },
editorOpts: { autoIndent: true }
editorOpts: { autoIndent: 'full' }
}, (model, cursor) => {
moveTo(cursor, 1, 12, false);
assertCursor(cursor, new Selection(1, 12, 1, 12));
......@@ -2857,7 +2857,7 @@ suite('Editor Controller - Indentation Rules', () => {
'\t'
],
languageIdentifier: mode.getLanguageIdentifier(),
editorOpts: { autoIndent: true }
editorOpts: { autoIndent: 'full' }
}, (model, cursor) => {
moveTo(cursor, 2, 2, false);
assertCursor(cursor, new Selection(2, 2, 2, 2));
......@@ -2876,7 +2876,7 @@ suite('Editor Controller - Indentation Rules', () => {
],
languageIdentifier: mode.getLanguageIdentifier(),
modelOpts: { insertSpaces: false },
editorOpts: { autoIndent: true }
editorOpts: { autoIndent: 'full' }
}, (model, cursor) => {
moveTo(cursor, 2, 15, false);
assertCursor(cursor, new Selection(2, 15, 2, 15));
......@@ -2896,7 +2896,7 @@ suite('Editor Controller - Indentation Rules', () => {
],
languageIdentifier: mode.getLanguageIdentifier(),
modelOpts: { insertSpaces: false },
editorOpts: { autoIndent: true }
editorOpts: { autoIndent: 'full' }
}, (model, cursor) => {
moveTo(cursor, 2, 14, false);
assertCursor(cursor, new Selection(2, 14, 2, 14));
......@@ -2924,7 +2924,7 @@ suite('Editor Controller - Indentation Rules', () => {
mode.getLanguageIdentifier()
);
withTestCodeEditor(null, { model: model, autoIndent: true }, (editor, cursor) => {
withTestCodeEditor(null, { model: model, autoIndent: 'full' }, (editor, cursor) => {
moveTo(cursor, 2, 11, false);
assertCursor(cursor, new Selection(2, 11, 2, 11));
......@@ -2948,7 +2948,7 @@ suite('Editor Controller - Indentation Rules', () => {
'}}'
],
languageIdentifier: mode.getLanguageIdentifier(),
editorOpts: { autoIndent: true }
editorOpts: { autoIndent: 'full' }
}, (model, cursor) => {
moveTo(cursor, 3, 13, false);
assertCursor(cursor, new Selection(3, 13, 3, 13));
......@@ -3084,7 +3084,7 @@ suite('Editor Controller - Indentation Rules', () => {
],
languageIdentifier: mode.getLanguageIdentifier(),
modelOpts: { insertSpaces: false },
editorOpts: { autoIndent: true }
editorOpts: { autoIndent: 'full' }
}, (model, cursor) => {
moveTo(cursor, 5, 4, false);
assertCursor(cursor, new Selection(5, 4, 5, 4));
......@@ -3554,7 +3554,7 @@ suite('Editor Controller - Indentation Rules', () => {
rubyMode.getLanguageIdentifier()
);
withTestCodeEditor(null, { model: model, autoIndent: true }, (editor, cursor) => {
withTestCodeEditor(null, { model: model, autoIndent: 'full' }, (editor, cursor) => {
moveTo(cursor, 4, 7, false);
assertCursor(cursor, new Selection(4, 7, 4, 7));
......@@ -3615,7 +3615,7 @@ suite('Editor Controller - Indentation Rules', () => {
'\t\t'
],
languageIdentifier: mode.getLanguageIdentifier(),
editorOpts: { autoIndent: true }
editorOpts: { autoIndent: 'full' }
}, (model, cursor) => {
moveTo(cursor, 3, 3, false);
assertCursor(cursor, new Selection(3, 3, 3, 3));
......@@ -3664,7 +3664,7 @@ suite('Editor Controller - Indentation Rules', () => {
mode.getLanguageIdentifier()
);
withTestCodeEditor(null, { model: model, autoIndent: false }, (editor, cursor) => {
withTestCodeEditor(null, { model: model, autoIndent: 'advanced' }, (editor, cursor) => {
moveTo(cursor, 7, 6, false);
assertCursor(cursor, new Selection(7, 6, 7, 6));
......@@ -3728,7 +3728,7 @@ suite('Editor Controller - Indentation Rules', () => {
mode.getLanguageIdentifier()
);
withTestCodeEditor(null, { model: model, autoIndent: false }, (editor, cursor) => {
withTestCodeEditor(null, { model: model, autoIndent: 'advanced' }, (editor, cursor) => {
moveTo(cursor, 8, 1, false);
assertCursor(cursor, new Selection(8, 1, 8, 1));
......@@ -3791,7 +3791,7 @@ suite('Editor Controller - Indentation Rules', () => {
mode.getLanguageIdentifier()
);
withTestCodeEditor(null, { model: model, autoIndent: true }, (editor, cursor) => {
withTestCodeEditor(null, { model: model, autoIndent: 'full' }, (editor, cursor) => {
moveTo(cursor, 3, 19, false);
assertCursor(cursor, new Selection(3, 19, 3, 19));
......
......@@ -6,6 +6,7 @@ import * as assert from 'assert';
import { CharacterPair, IndentAction } from 'vs/editor/common/modes/languageConfiguration';
import { OnEnterSupport } from 'vs/editor/common/modes/supports/onEnter';
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
import { EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions';
suite('OnEnter', () => {
......@@ -18,7 +19,7 @@ suite('OnEnter', () => {
brackets: brackets
});
let testIndentAction = (beforeText: string, afterText: string, expected: IndentAction) => {
let actual = support.onEnter('', beforeText, afterText);
let actual = support.onEnter(EditorAutoIndentStrategy.Advanced, '', beforeText, afterText);
if (expected === IndentAction.None) {
assert.equal(actual, null);
} else {
......@@ -51,7 +52,7 @@ suite('OnEnter', () => {
regExpRules: javascriptOnEnterRules
});
let testIndentAction = (oneLineAboveText: string, beforeText: string, afterText: string, expectedIndentAction: IndentAction | null, expectedAppendText: string | null, removeText: number = 0) => {
let actual = support.onEnter(oneLineAboveText, beforeText, afterText);
let actual = support.onEnter(EditorAutoIndentStrategy.Advanced, oneLineAboveText, beforeText, afterText);
if (expectedIndentAction === null) {
assert.equal(actual, null, 'isNull:' + beforeText);
} else {
......@@ -132,4 +133,4 @@ suite('OnEnter', () => {
testIndentAction('', ' * test() {', '', IndentAction.Indent, null, 0);
testIndentAction(' ', ' * test() {', '', IndentAction.Indent, null, 0);
});
});
\ No newline at end of file
});
......@@ -2775,7 +2775,7 @@ declare namespace monaco.editor {
* Enable auto indentation adjustment.
* Defaults to false.
*/
autoIndent?: boolean;
autoIndent?: 'none' | 'keep' | 'brackets' | 'advanced' | 'full';
/**
* Enable format on type.
* Defaults to false.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册