提交 62ed7707 编写于 作者: R rebornix

while handling onEnter for for moving lines, we still need to handle decrease...

while handling onEnter for for moving lines, we still need to handle decrease indent for moving line.
上级 b166434e
......@@ -592,6 +592,19 @@ export class LanguageConfigurationRegistryImpl {
return null;
}
public getIndentMetadata(model: ITokenizedModel, lineNumber: number): number {
let indentRulesSupport = this._getIndentRulesSupport(model.getLanguageIdentifier().id);
if (!indentRulesSupport) {
return null;
}
if (lineNumber < 1 || lineNumber > model.getLineCount()) {
return null;
}
return indentRulesSupport.getIndentMetadata(model.getLineContent(lineNumber));
}
// end Indent Rules
// begin onEnter
......
......@@ -7,6 +7,13 @@
import * as strings from 'vs/base/common/strings';
import { IndentationRule, IndentAction } from 'vs/editor/common/modes/languageConfiguration';
export const enum IndentConsts {
INCREASE_MASK = 0b00000001,
DECREASE_MASK = 0b00000010,
INDENT_NEXTLINE_MASK = 0b00000100,
UNINDENT_MASK = 0b00001000,
};
export class IndentRulesSupport {
private readonly _indentationRules: IndentationRule;
......@@ -74,5 +81,22 @@ export class IndentRulesSupport {
return false;
}
public getIndentMetadata(text: string): number {
let ret = 0;
if (this.shouldIncrease(text)) {
ret += IndentConsts.INCREASE_MASK;
}
if (this.shouldDecrease(text)) {
ret += IndentConsts.DECREASE_MASK;
}
if (this.shouldIndentNextLine(text)) {
ret += IndentConsts.INDENT_NEXTLINE_MASK;
}
if (this.shouldIgnore(text)) {
ret += IndentConsts.UNINDENT_MASK;
}
return ret;
}
}
......@@ -12,6 +12,7 @@ import { LanguageConfigurationRegistry, IIndentConverter } from 'vs/editor/commo
import { ShiftCommand } from 'vs/editor/common/commands/shiftCommand';
import * as IndentUtil from 'vs/editor/contrib/indentation/common/indentUtils';
import { IndentAction } from 'vs/editor/common/modes/languageConfiguration';
import { IndentConsts } from 'vs/editor/common/modes/supports/indentRules';
export class MoveLinesCommand implements ICommand {
......@@ -267,7 +268,7 @@ export class MoveLinesCommand implements ICommand {
} else if (enterAction.indentAction === IndentAction.Indent) {
enterPrefix = enter.indentation + enterAction.appendText;
} else if (enterAction.indentAction === IndentAction.IndentOutdent) {
enterPrefix = indentConverter.shiftIndent(enter.indentation) + enterAction.appendText;
enterPrefix = enter.indentation;
} else if (enterAction.indentAction === IndentAction.Outdent) {
enterPrefix = indentConverter.unshiftIndent(enter.indentation) + enterAction.appendText;
}
......@@ -275,6 +276,10 @@ export class MoveLinesCommand implements ICommand {
if (this.trimLeft(movingLineText).indexOf(this.trimLeft(enterPrefix)) >= 0) {
let oldIndentation = strings.getLeadingWhitespace(model.getLineContent(line));
let newIndentation = strings.getLeadingWhitespace(enterPrefix);
let indentMetadataOfMovelingLine = LanguageConfigurationRegistry.getIndentMetadata(model, line);
if (indentMetadataOfMovelingLine & IndentConsts.DECREASE_MASK) {
newIndentation = indentConverter.unshiftIndent(newIndentation);
}
let newSpaceCnt = IndentUtil.getSpaceCnt(newIndentation, tabSize);
let oldSpaceCnt = IndentUtil.getSpaceCnt(oldIndentation, tabSize);
return newSpaceCnt - oldSpaceCnt;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册