From e97e8ec64bfbf52cd589827a4ac681d0090db060 Mon Sep 17 00:00:00 2001 From: rebornix Date: Mon, 14 Aug 2017 14:36:30 -0700 Subject: [PATCH] Fix #30181. If the tokenization has not be executed for lines above pasted area, we do not force tokenization info as we do not wait for the tokenization to complete. --- src/vs/editor/common/editorCommon.ts | 5 +++++ src/vs/editor/common/model/textModelWithTokens.ts | 4 ++++ src/vs/editor/contrib/indentation/common/indentation.ts | 3 +++ 3 files changed, 12 insertions(+) diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index 2dec6f66b9c..93e9a28cf56 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -819,6 +819,11 @@ export interface ITokenizedModel extends ITextModel { */ forceTokenization(lineNumber: number): void; + /** + * Get the line number of the first line whose tokens might be inaccurate. + * @internal + */ + getFirstInvalidLineNumber(): number; /** * Get the tokens for the line `lineNumber`. * The tokens might be inaccurate. Use `forceTokenization` to ensure accurate tokens. diff --git a/src/vs/editor/common/model/textModelWithTokens.ts b/src/vs/editor/common/model/textModelWithTokens.ts index 9532cbc5e1e..eeeab138210 100644 --- a/src/vs/editor/common/model/textModelWithTokens.ts +++ b/src/vs/editor/common/model/textModelWithTokens.ts @@ -169,6 +169,10 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke return result; } + public getFirstInvalidLineNumber(): number { + return this._invalidLineStartIndex + 1; + } + public forceTokenization(lineNumber: number): void { if (lineNumber < 1 || lineNumber > this.getLineCount()) { throw new Error('Illegal value ' + lineNumber + ' for `lineNumber`'); diff --git a/src/vs/editor/contrib/indentation/common/indentation.ts b/src/vs/editor/contrib/indentation/common/indentation.ts index ee7c641330d..9c5873fc4bc 100644 --- a/src/vs/editor/contrib/indentation/common/indentation.ts +++ b/src/vs/editor/contrib/indentation/common/indentation.ts @@ -423,6 +423,9 @@ export class AutoIndentOnPaste implements IEditorContribution { } const model = this.editor.getModel(); + if (model.getFirstInvalidLineNumber() < range.getStartPosition().lineNumber) { + return; + } const { tabSize, insertSpaces } = model.getOptions(); this.editor.pushUndoStop(); let textEdits: TextEdit[] = []; -- GitLab