Skip to content

Commit d3a5dd9

Browse files
committed
re microsoft#102503. reveal range
1 parent 637d782 commit d3a5dd9

6 files changed

Lines changed: 65 additions & 4 deletions

File tree

src/vs/vscode.proposed.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,22 @@ declare module 'vscode' {
13681368
readonly end: number;
13691369
}
13701370

1371+
export enum NotebookEditorRevealType {
1372+
/**
1373+
* The range will be revealed with as little scrolling as possible.
1374+
*/
1375+
Default = 0,
1376+
/**
1377+
* The range will always be revealed in the center of the viewport.
1378+
*/
1379+
InCenter = 1,
1380+
/**
1381+
* If the range is outside the viewport, it will be revealed in the center of the viewport.
1382+
* Otherwise, it will be revealed with as little scrolling as possible.
1383+
*/
1384+
InCenterIfOutsideViewport = 2,
1385+
}
1386+
13711387
export interface NotebookEditor {
13721388
/**
13731389
* The document associated with this notebook editor.
@@ -1429,6 +1445,8 @@ declare module 'vscode' {
14291445
asWebviewUri(localResource: Uri): Uri;
14301446

14311447
edit(callback: (editBuilder: NotebookEditorCellEdit) => void): Thenable<boolean>;
1448+
1449+
revealRange(range: NotebookCellRange, revealType?: NotebookEditorRevealType): void;
14321450
}
14331451

14341452
export interface NotebookOutputSelector {

src/vs/workbench/api/browser/mainThreadNotebook.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
1717
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
1818
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
1919
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
20-
import { ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, CellEditType, CellKind, DisplayOrderKey, ICellEditOperation, IEditor, INotebookDocumentFilter, INotebookKernelInfo, NotebookCellMetadata, NotebookCellOutputsSplice, NotebookDocumentMetadata, NOTEBOOK_DISPLAY_ORDER, TransientMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
20+
import { ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, CellEditType, CellKind, DisplayOrderKey, ICellEditOperation, ICellRange, IEditor, INotebookDocumentFilter, INotebookKernelInfo, NotebookCellMetadata, NotebookCellOutputsSplice, NotebookDocumentMetadata, NOTEBOOK_DISPLAY_ORDER, TransientMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
2121
import { IMainNotebookController, INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
2222
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
23-
import { ExtHostContext, ExtHostNotebookShape, IExtHostContext, INotebookCellStatusBarEntryDto, INotebookDocumentsAndEditorsDelta, MainContext, MainThreadNotebookShape, NotebookExtensionDescription } from '../common/extHost.protocol';
23+
import { ExtHostContext, ExtHostNotebookShape, IExtHostContext, INotebookCellStatusBarEntryDto, INotebookDocumentsAndEditorsDelta, MainContext, MainThreadNotebookShape, NotebookEditorRevealType, NotebookExtensionDescription } from '../common/extHost.protocol';
2424

2525
class DocumentAndEditorState {
2626
static ofSets<T>(before: Set<T>, after: Set<T>): { removed: T[], added: T[] } {
@@ -612,6 +612,32 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
612612
textModel?.handleUnknownChange();
613613
}
614614

615+
async $tryRevealRange(id: string, range: ICellRange, revealType: NotebookEditorRevealType) {
616+
const editor = this._notebookService.listNotebookEditors().find(editor => editor.getId() === id);
617+
if (editor && editor.isNotebookEditor) {
618+
const notebookEditor = editor as INotebookEditor;
619+
const viewModel = notebookEditor.viewModel;
620+
const cell = viewModel?.viewCells[range.start];
621+
if (!cell) {
622+
return;
623+
}
624+
625+
switch (revealType) {
626+
case NotebookEditorRevealType.Default:
627+
notebookEditor.revealInView(cell);
628+
break;
629+
case NotebookEditorRevealType.InCenter:
630+
notebookEditor.revealInCenter(cell);
631+
break;
632+
case NotebookEditorRevealType.InCenterIfOutsideViewport:
633+
notebookEditor.revealInCenterIfOutsideViewport(cell);
634+
break;
635+
default:
636+
break;
637+
}
638+
}
639+
}
640+
615641
async $setStatusBarEntry(id: number, rawStatusBarEntry: INotebookCellStatusBarEntryDto): Promise<void> {
616642
const statusBarEntry = {
617643
...rawStatusBarEntry,

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
11381138
CellOutputKind: extHostTypes.CellOutputKind,
11391139
NotebookCellRunState: extHostTypes.NotebookCellRunState,
11401140
NotebookRunState: extHostTypes.NotebookRunState,
1141-
NotebookCellStatusBarAlignment: extHostTypes.NotebookCellStatusBarAlignment
1141+
NotebookCellStatusBarAlignment: extHostTypes.NotebookCellStatusBarAlignment,
1142+
NotebookEditorRevealType: extHostTypes.NotebookEditorRevealType
11421143
};
11431144
};
11441145
}

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,12 @@ export type NotebookCellOutputsSplice = [
720720
IProcessedOutput[]
721721
];
722722

723+
export enum NotebookEditorRevealType {
724+
Default = 0,
725+
InCenter = 1,
726+
InCenterIfOutsideViewport = 2,
727+
}
728+
723729
export type INotebookCellStatusBarEntryDto = Dto<INotebookCellStatusBarEntry>;
724730

725731
export interface MainThreadNotebookShape extends IDisposable {
@@ -738,7 +744,7 @@ export interface MainThreadNotebookShape extends IDisposable {
738744
$spliceNotebookCellOutputs(viewType: string, resource: UriComponents, cellHandle: number, splices: NotebookCellOutputsSplice[]): Promise<void>;
739745
$postMessage(editorId: string, forRendererId: string | undefined, value: any): Promise<boolean>;
740746
$setStatusBarEntry(id: number, statusBarEntry: INotebookCellStatusBarEntryDto): Promise<void>;
741-
747+
$tryRevealRange(id: string, range: ICellRange, revealType: NotebookEditorRevealType): Promise<void>;
742748
$onDidEdit(resource: UriComponents, viewType: string, editId: number, label: string | undefined): void;
743749
$onContentChange(resource: UriComponents, viewType: string): void;
744750
}

src/vs/workbench/api/common/extHostNotebook.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,10 @@ export class ExtHostNotebookEditor extends Disposable implements vscode.Notebook
747747
return this._proxy.$tryApplyEdits(this.viewType, this.uri, editData.documentVersionId, compressedEdits);
748748
}
749749

750+
revealRange(range: vscode.NotebookCellRange, revealType?: extHostTypes.NotebookEditorRevealType) {
751+
this._proxy.$tryRevealRange(this.id, range, revealType || extHostTypes.NotebookEditorRevealType.Default);
752+
}
753+
750754
get viewColumn(): vscode.ViewColumn | undefined {
751755
return this._viewColumn;
752756
}

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,6 +2785,12 @@ export enum NotebookCellStatusBarAlignment {
27852785
Right = 2
27862786
}
27872787

2788+
export enum NotebookEditorRevealType {
2789+
Default = 0,
2790+
InCenter = 1,
2791+
InCenterIfOutsideViewport = 2
2792+
}
2793+
27882794

27892795
//#endregion
27902796

0 commit comments

Comments
 (0)