Skip to content

Commit

Permalink
Fix #32508. Tokenize tokens when cheap
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Aug 19, 2017
1 parent f90f8ae commit 791f59f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/vs/editor/contrib/linesOperations/common/moveLinesCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class MoveLinesCommand implements ICommand {

let insertingText = movingLineText;

if (this.isAutoIndent(model, s)) {
if (this.shouldAutoIndent(model, s)) {
let movingLineMatchResult = this.matchEnterRule(model, indentConverter, tabSize, movingLineNumber, s.startLineNumber - 1);
// if s.startLineNumber - 1 matches onEnter rule, we still honor that.
if (movingLineMatchResult !== null) {
Expand Down Expand Up @@ -178,7 +178,7 @@ export class MoveLinesCommand implements ICommand {
// Insert line that needs to be moved after
builder.addEditOperation(new Range(s.endLineNumber, model.getLineMaxColumn(s.endLineNumber), s.endLineNumber, model.getLineMaxColumn(s.endLineNumber)), '\n' + movingLineText);

if (this.isAutoIndent(model, s)) {
if (this.shouldAutoIndent(model, s)) {
virtualModel.getLineContent = (lineNumber: number) => {
if (lineNumber === movingLineNumber) {
return model.getLineContent(s.startLineNumber);
Expand Down Expand Up @@ -261,7 +261,6 @@ export class MoveLinesCommand implements ICommand {
}

let maxColumn = model.getLineMaxColumn(validPrecedingLine);
// TODO@Peng TODO@forceTokenization: getEnterAction forces tokenization
let enter = LanguageConfigurationRegistry.getEnterAction(model, new Range(validPrecedingLine, maxColumn, validPrecedingLine, maxColumn));

if (enter) {
Expand Down Expand Up @@ -298,10 +297,14 @@ export class MoveLinesCommand implements ICommand {
return str.replace(/^\s+/, '');
}

private isAutoIndent(model: ITokenizedModel, selection: Selection) {
private shouldAutoIndent(model: ITokenizedModel, selection: Selection) {
if (!this._autoIndent) {
return false;
}
// if it's not easy to tokenize, we stop auto indent.
if (!model.isCheapToTokenize(selection.startLineNumber)) {
return false;
}
let languageAtSelectionStart = model.getLanguageIdAtPosition(selection.startLineNumber, 1);
let languageAtSelectionEnd = model.getLanguageIdAtPosition(selection.endLineNumber, 1);

Expand Down

0 comments on commit 791f59f

Please sign in to comment.