提交 5121bac4 编写于 作者: R rebornix

NotebookEditor.selection

上级 8b7ea333
......@@ -1688,7 +1688,15 @@ declare module 'vscode' {
}
export interface NotebookEditor {
/**
* The document associated with this notebook editor.
*/
readonly document: NotebookDocument;
/**
* The primary selected cell on this notebook editor.
*/
readonly selection?: NotebookCell;
viewColumn?: ViewColumn;
/**
* Fired when the output hosting webview posts a message.
......
......@@ -33,6 +33,10 @@ export class MainThreadNotebookDocument extends Disposable {
this._register(this._textModel.onDidModelChange(e => {
this._proxy.$acceptModelChanged(this.uri, e);
}));
this._register(this._textModel.onDidSelectionChange(e => {
const selectionsChange = e ? { selections: e } : null;
this._proxy.$acceptEditorPropertiesChanged(uri, { selections: selectionsChange });
}));
}
applyEdit(modelVersionId: number, edits: ICellEditOperation[]): boolean {
......
......@@ -1528,6 +1528,15 @@ export interface ExtHostCommentsShape {
$toggleReaction(commentControllerHandle: number, threadHandle: number, uri: UriComponents, comment: modes.Comment, reaction: modes.CommentReaction): Promise<void>;
}
export interface INotebookSelectionChangeEvent {
// handles
selections: number[];
}
export interface INotebookEditorPropertiesChangeData {
selections: INotebookSelectionChangeEvent | null;
}
export interface ExtHostNotebookShape {
$resolveNotebook(viewType: string, uri: UriComponents): Promise<number | undefined>;
$executeNotebook(viewType: string, uri: UriComponents, cellHandle: number | undefined, token: CancellationToken): Promise<void>;
......@@ -1537,6 +1546,7 @@ export interface ExtHostNotebookShape {
$acceptDisplayOrder(displayOrder: INotebookDisplayOrder): void;
$onDidReceiveMessage(uri: UriComponents, message: any): void;
$acceptModelChanged(uriComponents: UriComponents, event: NotebookCellsChangedEvent): void;
$acceptEditorPropertiesChanged(uriComponents: UriComponents, data: INotebookEditorPropertiesChangeData): void;
}
export interface ExtHostStorageShape {
......
......@@ -10,7 +10,7 @@ import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecyc
import { ISplice } from 'vs/base/common/sequence';
import { URI, UriComponents } from 'vs/base/common/uri';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { CellKind, CellOutputKind, ExtHostNotebookShape, IMainContext, MainContext, MainThreadNotebookShape, NotebookCellOutputsSplice, MainThreadDocumentsShape } from 'vs/workbench/api/common/extHost.protocol';
import { CellKind, CellOutputKind, ExtHostNotebookShape, IMainContext, MainContext, MainThreadNotebookShape, NotebookCellOutputsSplice, MainThreadDocumentsShape, INotebookEditorPropertiesChangeData } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import { CellEditType, CellUri, diff, ICellEditOperation, ICellInsertEdit, IErrorOutput, INotebookDisplayOrder, INotebookEditData, IOrderedMimeType, IStreamOutput, ITransformedDisplayOutputDto, mimeTypeSupportedByCore, NotebookCellsChangedEvent, NotebookCellsSplice2, sortMimeTypes, ICellDeleteEdit, notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon';
......@@ -459,6 +459,8 @@ export class NotebookEditorCellEdit {
export class ExtHostNotebookEditor extends Disposable implements vscode.NotebookEditor {
private _viewColumn: vscode.ViewColumn | undefined;
selection?: ExtHostCell = undefined;
onDidReceiveMessage: vscode.Event<any> = this._onDidReceiveMessage.event;
constructor(
......@@ -804,4 +806,23 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
}
}
$acceptEditorPropertiesChanged(uriComponents: UriComponents, data: INotebookEditorPropertiesChangeData): void {
let editor = this._editors.get(URI.revive(uriComponents).toString());
if (!editor) {
return;
}
if (data.selections) {
const cells = editor.editor.document.cells;
if (data.selections.selections.length) {
const firstCell = data.selections.selections[0];
editor.editor.selection = cells.find(cell => cell.handle === firstCell);
} else {
editor.editor.selection = undefined;
}
}
}
}
......@@ -344,6 +344,7 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
this.setFocus([index]);
}
}
selectElement(cell: ICellViewModel) {
const index = this._getViewIndexUpperBound(cell);
......@@ -353,6 +354,14 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
}
}
setFocus(indexes: number[], browserEvent?: UIEvent): void {
if (this._viewModel) {
this._viewModel.selections = indexes.map(index => this.element(index)).map(cell => cell.handle);
}
super.setFocus(indexes, browserEvent);
}
revealElementInView(cell: ICellViewModel) {
const index = this._getViewIndexUpperBound(cell);
......
......@@ -197,6 +197,17 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
return this._layoutInfo;
}
private _selections: number[] = [];
get selections() {
return this._selections;
}
set selections(selections: number[]) {
this._selections = selections;
this._model.notebook.selections = selections;
}
private _decorationsTree = new DecorationsTree();
private _decorations: { [decorationId: string]: IntervalNode; } = Object.create(null);
private _lastDecorationId: number = 0;
......
......@@ -18,6 +18,8 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
get onDidChangeCells(): Event<NotebookCellTextModelSplice[]> { return this._onDidChangeCells.event; }
private _onDidModelChangeProxy = new Emitter<NotebookCellsChangedEvent>();
get onDidModelChange(): Event<NotebookCellsChangedEvent> { return this._onDidModelChangeProxy.event; }
private _onDidSelectionChangeProxy = new Emitter<number[] | null>();
get onDidSelectionChange(): Event<number[] | null> { return this._onDidSelectionChangeProxy.event; }
private _onDidChangeContent = new Emitter<void>();
onDidChangeContent: Event<void> = this._onDidChangeContent.event;
private _onDidChangeMetadata = new Emitter<NotebookDocumentMetadata>();
......@@ -35,6 +37,17 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
return this._versionId;
}
private _selections: number[] = [];
get selections() {
return this._selections;
}
set selections(selections: number[]) {
this._selections = selections;
this._onDidSelectionChangeProxy.fire(this._selections);
}
constructor(
public handle: number,
public viewType: string,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册