From 61af4972f271dc06e3d310c9d563c21586ec3de0 Mon Sep 17 00:00:00 2001 From: Aaron Munger Date: Mon, 25 Sep 2023 11:36:17 -0700 Subject: [PATCH] better range usage --- .../notebook/browser/contrib/outline/notebookOutline.ts | 3 ++- .../contrib/notebook/browser/viewModel/OutlineEntry.ts | 9 +++++++-- .../browser/viewModel/notebookOutlineEntryFactory.ts | 3 +-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.ts b/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.ts index d49dbc36319c1..d93af0a7a1cbd 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.ts @@ -306,8 +306,9 @@ export class NotebookCellOutline implements IOutline { return Disposable.None; } + if (entry.range) { - const range = new Range(entry.range.startLineNumber, entry.range.startColumn, entry.range.endLineNumber, entry.range.endColumn); + const range = Range.lift(entry.range); widget.revealRangeInCenterIfOutsideViewportAsync(entry.cell, range); } else { widget.revealInCenterIfOutsideViewport(entry.cell); diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/OutlineEntry.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/OutlineEntry.ts index 512d3ab5afd07..398f676c876dd 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/OutlineEntry.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/OutlineEntry.ts @@ -11,7 +11,6 @@ import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { IRange } from 'vs/editor/common/core/range'; import { SymbolKind, SymbolKinds } from 'vs/editor/common/languages'; - export interface IOutlineMarkerInfo { readonly count: number; readonly topSev: MarkerSeverity; @@ -38,7 +37,6 @@ export class OutlineEntry { readonly label: string, readonly isExecuting: boolean, readonly isPaused: boolean, - readonly position?: IRange, readonly range?: IRange, readonly symbolKind?: SymbolKind, ) { } @@ -60,6 +58,13 @@ export class OutlineEntry { return this._markerInfo; } + get position() { + if (this.range) { + return { startLineNumber: this.range.startLineNumber, startColumn: this.range.startColumn }; + } + return undefined; + } + updateMarkers(markerService: IMarkerService): void { if (this.cell.cellKind === CellKind.Code) { // a code cell can have marker diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineEntryFactory.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineEntryFactory.ts index 2b985281be075..54335576ac92e 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineEntryFactory.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineEntryFactory.ts @@ -72,8 +72,7 @@ export class NotebookOutlineEntryFactory { // So symbols need to be precached before this function is called to get the full list. if (cachedEntries) { cachedEntries.forEach((cached) => { - const position = { ...cached.range, endLineNumber: cached.range.startLineNumber, endColumn: cached.range.startColumn }; - entries.push(new OutlineEntry(index++, cached.level, cell, cached.name, false, false, position, cached.range, cached.kind)); + entries.push(new OutlineEntry(index++, cached.level, cell, cached.name, false, false, cached.range, cached.kind)); }); } }