提交 6485f447 编写于 作者: R rebornix

remove emit selections.

上级 ed377f96
......@@ -52,12 +52,10 @@ export class JoinCellEdit implements IResourceUndoRedoElement {
const cell = this.editingDelegate.createCellViewModel(this._deletedRawCell);
if (this.direction === 'above') {
this.editingDelegate.insertCell(this.index, this._deletedRawCell);
this.editingDelegate.emitSelections([cell.handle]);
this.editingDelegate.insertCell(this.index, this._deletedRawCell, [cell.handle]);
cell.focusMode = CellFocusMode.Editor;
} else {
this.editingDelegate.insertCell(this.index, cell.model);
this.editingDelegate.emitSelections([this.cell.handle]);
this.editingDelegate.insertCell(this.index, cell.model, [this.cell.handle]);
this.cell.focusMode = CellFocusMode.Editor;
}
}
......@@ -72,8 +70,7 @@ export class JoinCellEdit implements IResourceUndoRedoElement {
{ range: this.inverseRange, text: this.insertContent }
]);
this.editingDelegate.deleteCell(this.index);
this.editingDelegate.emitSelections([this.cell.handle]);
this.editingDelegate.deleteCell(this.index, [this.cell.handle]);
this.cell.focusMode = CellFocusMode.Editor;
}
}
......@@ -110,10 +107,9 @@ export class SplitCellEdit implements IResourceUndoRedoElement {
this.cell.setSelections(this.selections);
for (let j = 1; j < this.cellContents.length; j++) {
this.editingDelegate.deleteCell(this.index + 1);
this.editingDelegate.deleteCell(this.index + 1, j === this.cellContents.length - 1 ? [this.cell.handle] : undefined);
}
this.editingDelegate.emitSelections([this.cell.handle]);
this.cell.focusMode = CellFocusMode.Editor;
}
......@@ -134,7 +130,6 @@ export class SplitCellEdit implements IResourceUndoRedoElement {
}
if (lastCell) {
this.editingDelegate.emitSelections([lastCell.handle]);
lastCell.focusMode = CellFocusMode.Editor;
}
}
......
......@@ -327,13 +327,10 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
if (e.kind === NotebookCellsChangeType.ChangeDocumentMetadata) {
this.eventDispatcher.emit([new NotebookMetadataChangedEvent(this._notebook.metadata)]);
}
}));
this._register(this._notebook.emitSelections(selections => {
// text model emit selection change (for example, undo/redo)
// we should update the selection handle wisely
// TODO, if the editor is note selected, undo/redo should not change the focused element selection
this.updateSelectionsFromEdits(selections);
if (e.endSelections) {
this.updateSelectionsFromEdits(e.endSelections);
}
}));
this._register(this.eventDispatcher.onDidChangeLayout((e) => {
......@@ -849,7 +846,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
insertContent,
cell,
{
insertCell: (index: number, cell: NotebookCellTextModel) => {
insertCell: (index: number, cell: NotebookCellTextModel, endSelections?: number[]) => {
this.insertCell(index, cell, true, false);
},
deleteCell: (index: number) => {
......@@ -903,7 +900,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
insertContent,
below,
{
insertCell: (index: number, cell: NotebookCellTextModel) => {
insertCell: (index: number, cell: NotebookCellTextModel, endSelections?: number[]) => {
this.insertCell(index, cell, true, false);
},
deleteCell: (index: number) => {
......
......@@ -12,11 +12,10 @@ import { NotebookCellMetadata } from 'vs/workbench/contrib/notebook/common/noteb
* It should not modify Undo/Redo stack
*/
export interface ITextCellEditingDelegate {
insertCell?(index: number, cell: NotebookCellTextModel): void;
deleteCell?(index: number): void;
insertCell?(index: number, cell: NotebookCellTextModel, endSelections?: number[]): void;
deleteCell?(index: number, endSelections?: number[]): void;
moveCell?(fromIndex: number, length: number, toIndex: number, beforeSelections: number[] | undefined, endSelections: number[] | undefined): void;
updateCellMetadata?(index: number, newMetadata: NotebookCellMetadata): void;
emitSelections(selections: number[]): void;
}
......@@ -38,20 +37,14 @@ export class InsertCellEdit implements IResourceUndoRedoElement {
throw new Error('Notebook Delete Cell not implemented for Undo/Redo');
}
this.editingDelegate.deleteCell(this.insertIndex);
if (this.beforedSelections) {
this.editingDelegate.emitSelections(this.beforedSelections);
}
this.editingDelegate.deleteCell(this.insertIndex, this.beforedSelections);
}
redo(): void {
if (!this.editingDelegate.insertCell) {
throw new Error('Notebook Insert Cell not implemented for Undo/Redo');
}
this.editingDelegate.insertCell(this.insertIndex, this.cell);
if (this.endSelections) {
this.editingDelegate.emitSelections(this.endSelections);
}
this.editingDelegate.insertCell(this.insertIndex, this.cell, this.endSelections);
}
}
......@@ -77,10 +70,7 @@ export class DeleteCellEdit implements IResourceUndoRedoElement {
throw new Error('Notebook Insert Cell not implemented for Undo/Redo');
}
this.editingDelegate.insertCell(this.insertIndex, this._cell);
if (this.beforedSelections) {
this.editingDelegate.emitSelections(this.beforedSelections);
}
this.editingDelegate.insertCell(this.insertIndex, this._cell, this.beforedSelections);
}
redo(): void {
......@@ -88,10 +78,7 @@ export class DeleteCellEdit implements IResourceUndoRedoElement {
throw new Error('Notebook Delete Cell not implemented for Undo/Redo');
}
this.editingDelegate.deleteCell(this.insertIndex);
if (this.endSelections) {
this.editingDelegate.emitSelections(this.endSelections);
}
this.editingDelegate.deleteCell(this.insertIndex, this.endSelections);
}
}
......@@ -116,9 +103,6 @@ export class MoveCellEdit implements IResourceUndoRedoElement {
}
this.editingDelegate.moveCell(this.toIndex, this.length, this.fromIndex, this.endSelections, this.beforedSelections);
if (this.beforedSelections) {
this.editingDelegate.emitSelections(this.beforedSelections);
}
}
redo(): void {
......@@ -127,9 +111,6 @@ export class MoveCellEdit implements IResourceUndoRedoElement {
}
this.editingDelegate.moveCell(this.fromIndex, this.length, this.toIndex, this.beforedSelections, this.endSelections);
if (this.endSelections) {
this.editingDelegate.emitSelections(this.endSelections);
}
}
}
......@@ -152,17 +133,13 @@ export class SpliceCellsEdit implements IResourceUndoRedoElement {
this.diffs.forEach(diff => {
for (let i = 0; i < diff[2].length; i++) {
this.editingDelegate.deleteCell!(diff[0]);
this.editingDelegate.deleteCell!(diff[0], this.beforeHandles);
}
diff[1].reverse().forEach(cell => {
this.editingDelegate.insertCell!(diff[0], cell);
this.editingDelegate.insertCell!(diff[0], cell, this.beforeHandles);
});
});
if (this.beforeHandles) {
this.editingDelegate.emitSelections(this.beforeHandles);
}
}
redo(): void {
......@@ -172,17 +149,13 @@ export class SpliceCellsEdit implements IResourceUndoRedoElement {
this.diffs.reverse().forEach(diff => {
for (let i = 0; i < diff[1].length; i++) {
this.editingDelegate.deleteCell!(diff[0]);
this.editingDelegate.deleteCell!(diff[0], this.endHandles);
}
diff[2].reverse().forEach(cell => {
this.editingDelegate.insertCell!(diff[0], cell);
this.editingDelegate.insertCell!(diff[0], cell, this.endHandles);
});
});
if (this.endHandles) {
this.editingDelegate.emitSelections(this.endHandles);
}
}
}
......
......@@ -148,8 +148,6 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
readonly onDidChangeDirty = this._onDidChangeDirty.event;
private _onDidChangeContent = this._register(new Emitter<NotebookTextModelChangedEvent>());
get onDidChangeContent(): Event<NotebookTextModelChangedEvent> { return this._onDidChangeContent.event; }
private readonly _emitSelections = this._register(new Emitter<number[]>());
get emitSelections() { return this._emitSelections.event; }
private _mapping: Map<number, NotebookCellTextModel> = new Map();
private _cellListeners: Map<number, IDisposable> = new Map();
cells: NotebookCellTextModel[];
......@@ -353,9 +351,8 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
});
this._operationManager.pushEditOperation(new SpliceCellsEdit(this.uri, undoDiff, {
insertCell: (index, cell) => { this._insertNewCell(index, [cell], true); },
deleteCell: (index) => { this._removeCell(index, 1, true); },
emitSelections: (selections) => { this._emitSelections.fire(selections); }
insertCell: (index, cell, endSelections?: number[]) => { this._insertNewCell(index, [cell], true, endSelections); },
deleteCell: (index, endSelections?: number[]) => { this._removeCell(index, 1, true, endSelections); },
}, undefined, undefined));
// should be deferred
......@@ -469,7 +466,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
return;
}
private _insertNewCell(index: number, cells: NotebookCellTextModel[], synchronous: boolean): void {
private _insertNewCell(index: number, cells: NotebookCellTextModel[], synchronous: boolean, endSelections?: number[]): void {
this._isUntitled = false;
for (let i = 0; i < cells.length; i++) {
......@@ -496,7 +493,8 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
0,
cells
]],
synchronous
synchronous,
endSelections: endSelections
}
}
});
......@@ -504,7 +502,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
return;
}
private _removeCell(index: number, count: number, synchronous: boolean) {
private _removeCell(index: number, count: number, synchronous: boolean, endSelections?: number[]) {
this._isUntitled = false;
for (let i = index; i < index + count; i++) {
......@@ -515,7 +513,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
this.cells.splice(index, count);
this._eventEmitter.emit({
triggerDirty: { value: true },
modelContentChange: { value: { kind: NotebookCellsChangeType.ModelChange, versionId: this._versionId, changes: [[index, count, []]], synchronous } }
modelContentChange: { value: { kind: NotebookCellsChangeType.ModelChange, versionId: this._versionId, changes: [[index, count, []]], synchronous, endSelections } }
});
}
......@@ -553,8 +551,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
return;
}
this._changeCellMetadata(cell.handle, newMetadata, false);
},
emitSelections: (selections) => { this._emitSelections.fire(selections); }
}
}));
}
// should be deferred
......@@ -617,33 +614,24 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
insertCell(index: number, cell: NotebookCellTextModel, synchronous: boolean, pushUndoStop: boolean, beforeSelections: number[] | undefined, endSelections: number[] | undefined): void {
if (pushUndoStop) {
this._operationManager.pushEditOperation(new InsertCellEdit(this.uri, index, cell, {
insertCell: (index, cell) => { this._insertNewCell(index, [cell], true); },
deleteCell: (index) => { this._removeCell(index, 1, true); },
emitSelections: (selections) => { this._emitSelections.fire(selections); }
insertCell: (index, cell, endSelections) => { this._insertNewCell(index, [cell], true, endSelections); },
deleteCell: (index, endSelections) => { this._removeCell(index, 1, true, endSelections); },
}, beforeSelections, endSelections));
}
this._insertNewCell(index, [cell], synchronous);
if (endSelections) {
this._emitSelections.fire(endSelections);
}
this._insertNewCell(index, [cell], synchronous, endSelections);
}
deleteCell(index: number, synchronous: boolean, pushUndoStop: boolean, beforeSelections: number[] | undefined, endSelections: number[] | undefined) {
const cell = this.cells[index];
if (pushUndoStop) {
this._operationManager.pushEditOperation(new DeleteCellEdit(this.uri, index, cell, {
insertCell: (index, cell) => { this._insertNewCell(index, [cell], true); },
deleteCell: (index) => { this._removeCell(index, 1, true); },
emitSelections: (selections) => { this._emitSelections.fire(selections); }
insertCell: (index, cell, endSelections) => { this._insertNewCell(index, [cell], true, endSelections); },
deleteCell: (index, endSelections) => { this._removeCell(index, 1, true, endSelections); },
}, beforeSelections, endSelections));
}
this._removeCell(index, 1, synchronous);
if (endSelections) {
this._emitSelections.fire(endSelections);
}
this._removeCell(index, 1, synchronous, endSelections);
}
moveCellToIdx(index: number, length: number, newIdx: number, synchronous: boolean, pushedToUndoStack: boolean, beforeSelections: number[] | undefined, endSelections: number[] | undefined): boolean {
......@@ -652,7 +640,6 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
moveCell: (fromIndex: number, length: number, toIndex: number, beforeSelections: number[] | undefined, endSelections: number[] | undefined) => {
this.moveCellToIdx(fromIndex, length, toIndex, true, false, beforeSelections, endSelections);
},
emitSelections: (selections) => { this._emitSelections.fire(selections); }
}, beforeSelections, endSelections));
}
......@@ -664,16 +651,10 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
this.cells.splice(newIdx, 0, ...cells);
this._eventEmitter.emit({
triggerDirty: { value: true },
modelContentChange: { value: { kind: NotebookCellsChangeType.Move, versionId: this._versionId, index, length, newIdx, cells, synchronous } }
modelContentChange: { value: { kind: NotebookCellsChangeType.Move, versionId: this._versionId, index, length, newIdx, cells, synchronous, endSelections } }
});
}
// todo, we can't emit this change as it will create a new view model and that will hold
// a new reference to the document, thus
if (endSelections) {
this._emitSelections.fire(endSelections);
}
return true;
}
......@@ -696,13 +677,9 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
const newCells = [];
for (let j = 1; j < newLinesContents.length; j++, insertIndex++) {
const cell = this.createCellTextModel(newLinesContents[j], language, kind, [], undefined);
this.insertCell(insertIndex, cell, true, false, undefined, undefined);
this.insertCell(insertIndex, cell, true, false, undefined, j === newLinesContents.length - 1 ? endSelections : undefined);
newCells.push(cell);
}
if (endSelections) {
this._emitSelections.fire(endSelections);
}
}
//#endregion
......
......@@ -407,7 +407,7 @@ export interface NotebookDocumentChangeMetadataEvent {
}
export type NotebookCellsChangedEventDto = NotebookCellsInitializeEvent<IMainCellDto> | NotebookDocumentChangeMetadataEvent | NotebookCellContentChangeEvent | NotebookCellsModelChangedEvent<IMainCellDto> | NotebookCellsModelMoveEvent<IMainCellDto> | NotebookOutputChangedEvent | NotebookCellsChangeLanguageEvent | NotebookCellsChangeMetadataEvent;
export type NotebookTextModelChangedEvent = (NotebookCellsInitializeEvent<ICell> | NotebookDocumentChangeMetadataEvent | NotebookCellContentChangeEvent | NotebookCellsModelChangedEvent<ICell> | NotebookCellsModelMoveEvent<ICell> | NotebookOutputChangedEvent | NotebookCellsChangeLanguageEvent | NotebookCellsChangeMetadataEvent) & { synchronous: boolean; };
export type NotebookTextModelChangedEvent = (NotebookCellsInitializeEvent<ICell> | NotebookDocumentChangeMetadataEvent | NotebookCellContentChangeEvent | NotebookCellsModelChangedEvent<ICell> | NotebookCellsModelMoveEvent<ICell> | NotebookOutputChangedEvent | NotebookCellsChangeLanguageEvent | NotebookCellsChangeMetadataEvent) & { synchronous: boolean; endSelections?: number[] };
export const enum CellEditType {
Replace = 1,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册