diff options
author | Alexandru Dima <alexdima@microsoft.com> | 2022-07-28 16:10:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-28 16:10:19 +0300 |
commit | 95fd5bf198bc9f0083421ce5a53c05ca0294a7fd (patch) | |
tree | e25cf40d1f9776571d565813262a2f5cdc4479ff /src | |
parent | 0397ca4a4843cca225a88810c95bc60da537ca45 (diff) |
Make sure to use view line numbers when fetching data from the view model (#156569)
Fixes #156413: Make sure to use view line numbers when fetching data from the view model
Co-authored-by: aiday-mar <t-aidaym@microsoft.com>
Co-authored-by: aiday-mar <t-aidaym@microsoft.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/vs/editor/common/viewModel.ts | 1 | ||||
-rw-r--r-- | src/vs/editor/common/viewModel/viewModelDecorations.ts | 14 | ||||
-rw-r--r-- | src/vs/editor/common/viewModel/viewModelImpl.ts | 15 | ||||
-rw-r--r-- | src/vs/editor/contrib/stickyScroll/browser/stickyScroll.ts | 15 |
4 files changed, 31 insertions, 14 deletions
diff --git a/src/vs/editor/common/viewModel.ts b/src/vs/editor/common/viewModel.ts index 06e3164ba07..d4b67391d99 100644 --- a/src/vs/editor/common/viewModel.ts +++ b/src/vs/editor/common/viewModel.ts @@ -42,6 +42,7 @@ export interface IViewModel extends ICursorSimpleModel { getDecorationsInViewport(visibleRange: Range): ViewModelDecoration[]; getViewportViewLineRenderingData(visibleRange: Range, lineNumber: number): ViewLineRenderingData; + getViewLineRenderingData(lineNumber: number): ViewLineRenderingData; getViewLineData(lineNumber: number): ViewLineData; getMinimapLinesRenderingData(startLineNumber: number, endLineNumber: number, needed: boolean[]): MinimapLinesRenderingData; getCompletelyVisibleViewRange(): Range; diff --git a/src/vs/editor/common/viewModel/viewModelDecorations.ts b/src/vs/editor/common/viewModel/viewModelDecorations.ts index 909d9f19bc3..25edc82d950 100644 --- a/src/vs/editor/common/viewModel/viewModelDecorations.ts +++ b/src/vs/editor/common/viewModel/viewModelDecorations.ts @@ -100,17 +100,21 @@ export class ViewModelDecorations implements IDisposable { let cacheIsValid = (this._cachedModelDecorationsResolver !== null); cacheIsValid = cacheIsValid && (viewRange.equalsRange(this._cachedModelDecorationsResolverViewRange)); if (!cacheIsValid) { - this._cachedModelDecorationsResolver = this._getDecorationsViewportData(viewRange); + this._cachedModelDecorationsResolver = this._getDecorationsInRange(viewRange); this._cachedModelDecorationsResolverViewRange = viewRange; } return this._cachedModelDecorationsResolver!; } - private _getDecorationsViewportData(viewportRange: Range): IDecorationsViewportData { - const modelDecorations = this._linesCollection.getDecorationsInRange(viewportRange, this.editorId, filterValidationDecorations(this.configuration.options)); + public getInlineDecorationsOnLine(lineNumber: number): InlineDecoration[] { + const range = new Range(lineNumber, this._linesCollection.getViewLineMinColumn(lineNumber), lineNumber, this._linesCollection.getViewLineMaxColumn(lineNumber)); + return this._getDecorationsInRange(range).inlineDecorations[0]; + } - const startLineNumber = viewportRange.startLineNumber; - const endLineNumber = viewportRange.endLineNumber; + private _getDecorationsInRange(viewRange: Range): IDecorationsViewportData { + const modelDecorations = this._linesCollection.getDecorationsInRange(viewRange, this.editorId, filterValidationDecorations(this.configuration.options)); + const startLineNumber = viewRange.startLineNumber; + const endLineNumber = viewRange.endLineNumber; const decorationsInViewport: ViewModelDecoration[] = []; let decorationsInViewportLen = 0; diff --git a/src/vs/editor/common/viewModel/viewModelImpl.ts b/src/vs/editor/common/viewModel/viewModelImpl.ts index a990823ab9d..160d63c8b33 100644 --- a/src/vs/editor/common/viewModel/viewModelImpl.ts +++ b/src/vs/editor/common/viewModel/viewModelImpl.ts @@ -34,7 +34,7 @@ import { ViewLayout } from 'vs/editor/common/viewLayout/viewLayout'; import { MinimapTokensColorTracker } from 'vs/editor/common/viewModel/minimapTokensColorTracker'; import { ILineBreaksComputer, ILineBreaksComputerFactory, InjectedText } from 'vs/editor/common/modelLineProjectionData'; import { ViewEventHandler } from 'vs/editor/common/viewEventHandler'; -import { ICoordinatesConverter, IViewModel, IWhitespaceChangeAccessor, MinimapLinesRenderingData, OverviewRulerDecorationsGroup, ViewLineData, ViewLineRenderingData, ViewModelDecoration } from 'vs/editor/common/viewModel'; +import { ICoordinatesConverter, InlineDecoration, IViewModel, IWhitespaceChangeAccessor, MinimapLinesRenderingData, OverviewRulerDecorationsGroup, ViewLineData, ViewLineRenderingData, ViewModelDecoration } from 'vs/editor/common/viewModel'; import { ViewModelDecorations } from 'vs/editor/common/viewModel/viewModelDecorations'; import { FocusChangedEvent, ModelContentChangedEvent, ModelDecorationsChangedEvent, ModelLanguageChangedEvent, ModelLanguageConfigurationChangedEvent, ModelOptionsChangedEvent, ModelTokensChangedEvent, OutgoingViewModelEvent, ReadOnlyEditAttemptEvent, ScrollChangedEvent, ViewModelEventDispatcher, ViewModelEventsCollector, ViewZonesChangedEvent } from 'vs/editor/common/viewModelEventDispatcher'; import { IViewModelLines, ViewModelLinesFromModelAsIs, ViewModelLinesFromProjectedModel } from 'vs/editor/common/viewModel/viewModelLines'; @@ -680,12 +680,21 @@ export class ViewModel extends Disposable implements IViewModel { } public getViewportViewLineRenderingData(visibleRange: Range, lineNumber: number): ViewLineRenderingData { + const allInlineDecorations = this._decorations.getDecorationsViewportData(visibleRange).inlineDecorations; + const inlineDecorations = allInlineDecorations[lineNumber - visibleRange.startLineNumber]; + return this._getViewLineRenderingData(lineNumber, inlineDecorations); + } + + public getViewLineRenderingData(lineNumber: number): ViewLineRenderingData { + const inlineDecorations = this._decorations.getInlineDecorationsOnLine(lineNumber); + return this._getViewLineRenderingData(lineNumber, inlineDecorations); + } + + private _getViewLineRenderingData(lineNumber: number, inlineDecorations: InlineDecoration[]): ViewLineRenderingData { const mightContainRTL = this.model.mightContainRTL(); const mightContainNonBasicASCII = this.model.mightContainNonBasicASCII(); const tabSize = this.getTabSize(); const lineData = this._lines.getViewLineData(lineNumber); - const allInlineDecorations = this._decorations.getDecorationsViewportData(visibleRange).inlineDecorations; - let inlineDecorations = allInlineDecorations[lineNumber - visibleRange.startLineNumber]; if (lineData.inlineDecorations) { inlineDecorations = [ diff --git a/src/vs/editor/contrib/stickyScroll/browser/stickyScroll.ts b/src/vs/editor/contrib/stickyScroll/browser/stickyScroll.ts index d7f669d3caa..899d3db5fc6 100644 --- a/src/vs/editor/contrib/stickyScroll/browser/stickyScroll.ts +++ b/src/vs/editor/contrib/stickyScroll/browser/stickyScroll.ts @@ -18,6 +18,7 @@ import { SymbolKind } from 'vs/editor/common/languages'; import { LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations'; import { RunOnceScheduler } from 'vs/base/common/async'; import { IModelTokensChangedEvent } from 'vs/editor/common/textModelEvents'; +import { Position } from 'vs/editor/common/core/position'; class StickyScrollController extends Disposable implements IEditorContribution { @@ -201,12 +202,12 @@ class StickyScrollController extends Disposable implements IEditorContribution { if (!beginningLinesConsidered.has(start)) { if (topOfElementAtDepth >= topOfEndLine - 1 && topOfElementAtDepth < bottomOfEndLine - 2) { beginningLinesConsidered.add(start); - this.stickyScrollWidget.pushCodeLine(new StickyScrollCodeLine(model.getLineContent(start), start, this._editor, -1, bottomOfEndLine - bottomOfElementAtDepth)); + this.stickyScrollWidget.pushCodeLine(new StickyScrollCodeLine(start, this._editor, -1, bottomOfEndLine - bottomOfElementAtDepth)); break; } else if (bottomOfElementAtDepth > bottomOfBeginningLine - 1 && bottomOfElementAtDepth < bottomOfEndLine - 1) { beginningLinesConsidered.add(start); - this.stickyScrollWidget.pushCodeLine(new StickyScrollCodeLine(model.getLineContent(start), start, this._editor, 0, 0)); + this.stickyScrollWidget.pushCodeLine(new StickyScrollCodeLine(start, this._editor, 0, 0)); } } else { this._ranges.splice(index, 1); @@ -228,7 +229,7 @@ class StickyScrollCodeLine { public readonly effectiveLineHeight: number = 0; - constructor(private readonly _line: string, private readonly _lineNumber: number, private readonly _editor: IActiveCodeEditor, + constructor(private readonly _lineNumber: number, private readonly _editor: IActiveCodeEditor, private readonly _zIndex: number, private readonly _relativePosition: number) { this.effectiveLineHeight = this._editor.getOption(EditorOption.lineHeight) + this._relativePosition; } @@ -240,16 +241,18 @@ class StickyScrollCodeLine { getDomNode() { const root: HTMLElement = document.createElement('div'); - const lineRenderingData = this._editor._getViewModel().getViewportViewLineRenderingData(this._editor.getVisibleRangesPlusViewportAboveBelow()[0], this._lineNumber); + const viewModel = this._editor._getViewModel(); + const viewLineNumber = viewModel.coordinatesConverter.convertModelPositionToViewPosition(new Position(this._lineNumber, 1)).lineNumber; + const lineRenderingData = viewModel.getViewLineRenderingData(viewLineNumber); let actualInlineDecorations: LineDecoration[]; try { - actualInlineDecorations = LineDecoration.filter(lineRenderingData.inlineDecorations, this._lineNumber, lineRenderingData.minColumn, lineRenderingData.maxColumn); + actualInlineDecorations = LineDecoration.filter(lineRenderingData.inlineDecorations, viewLineNumber, lineRenderingData.minColumn, lineRenderingData.maxColumn); } catch (err) { actualInlineDecorations = []; } - const renderLineInput: RenderLineInput = new RenderLineInput(true, true, this._line, lineRenderingData.continuesWithWrappedLine, + const renderLineInput: RenderLineInput = new RenderLineInput(true, true, lineRenderingData.content, lineRenderingData.continuesWithWrappedLine, lineRenderingData.isBasicASCII, lineRenderingData.containsRTL, 0, lineRenderingData.tokens, actualInlineDecorations, lineRenderingData.tabSize, lineRenderingData.startVisibleColumn, 1, 1, 1, 100, 'none', true, true, null); |