From 34305abdce304d611e87fec6512b9be3baccd11c Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Tue, 3 Oct 2023 11:17:24 -0700 Subject: [PATCH] more getlinelength. re #193427. (#194737) * more getlinelength. re #193427. * more :lipstick: * :lipstick: --- src/vs/editor/common/cursor/cursorMoveCommands.ts | 4 ++-- .../contrib/codeEditor/browser/saveParticipants.ts | 4 ++-- .../contrib/debug/browser/debugEditorContribution.ts | 6 +++--- .../contrib/interactive/browser/interactiveEditor.ts | 2 +- .../contrib/preferences/common/smartSnippetInserter.ts | 2 +- .../services/untitled/common/untitledTextEditorModel.ts | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/vs/editor/common/cursor/cursorMoveCommands.ts b/src/vs/editor/common/cursor/cursorMoveCommands.ts index 6bc30328cb7..fae0d3f1fa8 100644 --- a/src/vs/editor/common/cursor/cursorMoveCommands.ts +++ b/src/vs/editor/common/cursor/cursorMoveCommands.ts @@ -443,7 +443,7 @@ export class CursorMoveCommands { for (let i = 0, len = cursors.length; i < len; i++) { const cursor = cursors[i]; const viewLineNumber = cursor.viewState.position.lineNumber; - const halfLine = Math.round(viewModel.getLineContent(viewLineNumber).length / 2); + const halfLine = Math.round(viewModel.getLineLength(viewLineNumber) / 2); result[i] = CursorState.fromViewState(MoveOperations.moveLeft(viewModel.cursorConfig, viewModel, cursor.viewState, inSelectionMode, halfLine)); } return result; @@ -462,7 +462,7 @@ export class CursorMoveCommands { for (let i = 0, len = cursors.length; i < len; i++) { const cursor = cursors[i]; const viewLineNumber = cursor.viewState.position.lineNumber; - const halfLine = Math.round(viewModel.getLineContent(viewLineNumber).length / 2); + const halfLine = Math.round(viewModel.getLineLength(viewLineNumber) / 2); result[i] = CursorState.fromViewState(MoveOperations.moveRight(viewModel.cursorConfig, viewModel, cursor.viewState, inSelectionMode, halfLine)); } return result; diff --git a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts index d29cbedb139..3ff57c9ceb3 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts @@ -160,8 +160,8 @@ export class TrimFinalNewLinesParticipant implements ITextFileSaveParticipant { */ private findLastNonEmptyLine(model: ITextModel): number { for (let lineNumber = model.getLineCount(); lineNumber >= 1; lineNumber--) { - const lineContent = model.getLineContent(lineNumber); - if (lineContent.length > 0) { + const lineLength = model.getLineLength(lineNumber); + if (lineLength > 0) { // this line has content return lineNumber; } diff --git a/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts b/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts index 7bd1e7ca57e..753beae7e23 100644 --- a/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts +++ b/src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts @@ -175,13 +175,13 @@ function getWordToLineNumbersMap(model: ITextModel | null): Map MAX_TOKENIZATION_LINE_LEN) { + if (lineLength > MAX_TOKENIZATION_LINE_LEN) { continue; } + const lineContent = model.getLineContent(lineNumber); model.tokenization.forceTokenization(lineNumber); const lineTokens = model.tokenization.getLineTokens(lineNumber); for (let tokenIndex = 0, tokenCount = lineTokens.getCount(); tokenIndex < tokenCount; tokenIndex++) { diff --git a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts index 30fff709556..11644704a78 100644 --- a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts +++ b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts @@ -506,7 +506,7 @@ export class InteractiveEditor extends EditorPane { this._widgetDisposableStore.add(this._codeEditorWidget.onDidChangeCursorPosition(({ position }) => { const viewModel = this._codeEditorWidget._getViewModel()!; const lastLineNumber = viewModel.getLineCount(); - const lastLineCol = viewModel.getLineContent(lastLineNumber).length + 1; + const lastLineCol = viewModel.getLineLength(lastLineNumber) + 1; const viewPosition = viewModel.coordinatesConverter.convertModelPositionToViewPosition(position); const firstLine = viewPosition.lineNumber === 1 && viewPosition.column === 1; const lastLine = viewPosition.lineNumber === lastLineNumber && viewPosition.column === lastLineCol; diff --git a/src/vs/workbench/contrib/preferences/common/smartSnippetInserter.ts b/src/vs/workbench/contrib/preferences/common/smartSnippetInserter.ts index 3ede58bd5fb..188ddea4d3e 100644 --- a/src/vs/workbench/contrib/preferences/common/smartSnippetInserter.ts +++ b/src/vs/workbench/contrib/preferences/common/smartSnippetInserter.ts @@ -34,7 +34,7 @@ export class SmartSnippetInserter { const eolLength = model.getEOL().length; const lineCount = model.getLineCount(); for (let lineNumber = 1; lineNumber <= lineCount; lineNumber++) { - const lineTotalLength = model.getLineContent(lineNumber).length + eolLength; + const lineTotalLength = model.getLineLength(lineNumber) + eolLength; const offsetAfterLine = offsetBeforeLine + lineTotalLength; if (offsetAfterLine > offset) { diff --git a/src/vs/workbench/services/untitled/common/untitledTextEditorModel.ts b/src/vs/workbench/services/untitled/common/untitledTextEditorModel.ts index 4b745f7af41..06ab35ec8c5 100644 --- a/src/vs/workbench/services/untitled/common/untitledTextEditorModel.ts +++ b/src/vs/workbench/services/untitled/common/untitledTextEditorModel.ts @@ -378,7 +378,7 @@ export class UntitledTextEditorModel extends BaseTextEditorModel implements IUnt // mark the untitled text editor as non-dirty once its content becomes empty and we do // not have an associated path set. we never want dirty indicator in that case. - if (!this.hasAssociatedFilePath && textEditorModel.getLineCount() === 1 && textEditorModel.getLineContent(1) === '') { + if (!this.hasAssociatedFilePath && textEditorModel.getLineCount() === 1 && textEditorModel.getLineLength(1) === 0) { this.setDirty(false); }