提交 54a2a821 编写于 作者: R rebornix

join cells through workspaceEdits

上级 bb7b1ef6
...@@ -29,8 +29,6 @@ import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/no ...@@ -29,8 +29,6 @@ import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/no
import { MarkdownRenderer } from 'vs/workbench/contrib/notebook/browser/view/renderers/mdRenderer'; import { MarkdownRenderer } from 'vs/workbench/contrib/notebook/browser/view/renderers/mdRenderer';
import { dirname } from 'vs/base/common/resources'; import { dirname } from 'vs/base/common/resources';
import { IPosition, Position } from 'vs/editor/common/core/position'; import { IPosition, Position } from 'vs/editor/common/core/position';
import { JoinCellEdit } from 'vs/workbench/contrib/notebook/browser/viewModel/cellEdit';
import { PieceTreeTextBuffer } from 'vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer';
import { MultiModelEditStackElement, SingleModelEditStackElement } from 'vs/editor/common/model/editStack'; import { MultiModelEditStackElement, SingleModelEditStackElement } from 'vs/editor/common/model/editStack';
import { ResourceNotebookCellEdit } from 'vs/workbench/contrib/bulkEdit/browser/bulkCellEdits'; import { ResourceNotebookCellEdit } from 'vs/workbench/contrib/bulkEdit/browser/bulkCellEdits';
...@@ -879,33 +877,20 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD ...@@ -879,33 +877,20 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
const insertContent = (cell.textModel?.getEOL() ?? '') + cell.getText(); const insertContent = (cell.textModel?.getEOL() ?? '') + cell.getText();
const aboveCellLineCount = above.textModel.getLineCount(); const aboveCellLineCount = above.textModel.getLineCount();
const aboveCellLastLineEndColumn = above.textModel.getLineLength(aboveCellLineCount); const aboveCellLastLineEndColumn = above.textModel.getLineLength(aboveCellLineCount);
const editOperation = { range: new Range(aboveCellLineCount, aboveCellLastLineEndColumn + 1, aboveCellLineCount, aboveCellLastLineEndColumn + 1), text: insertContent };
const editorSelections = above.getSelections();
above.textModel.applyEdits([editOperation]);
const inverseRange = PieceTreeTextBuffer._getInverseEditRange(editOperation.range, editOperation.text);
await this.deleteCell(index, true, false); await this._bulkEditService.apply(
[
this._undoService.pushElement(new JoinCellEdit( new ResourceTextEdit(above.uri, { range: new Range(aboveCellLineCount, aboveCellLastLineEndColumn + 1, aboveCellLineCount, aboveCellLastLineEndColumn + 1), text: insertContent }),
this.uri, new ResourceNotebookCellEdit(this._notebook.uri,
index, {
direction, editType: CellEditType.Replace,
above, index: index,
editorSelections, count: 1,
inverseRange, cells: []
insertContent, }
cell, )
{ ],
insertCell: (index: number, cell: NotebookCellTextModel, endSelections?: number[]) => { { quotableLabel: 'Join Notebook Cells' }
this.createCell(index, cell.getValue(), cell.language, cell.cellKind, cell.metadata, cell.outputs, true, false);
},
deleteCell: (index: number) => {
this.deleteCell(index, true, false);
},
createCellViewModel: (cell: NotebookCellTextModel) => {
return createCellViewModel(this._instantiationService, this, cell);
}
})
); );
this.selectionHandles = endSelections; this.selectionHandles = endSelections;
...@@ -930,33 +915,20 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD ...@@ -930,33 +915,20 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
const cellLineCount = cell.textModel.getLineCount(); const cellLineCount = cell.textModel.getLineCount();
const cellLastLineEndColumn = cell.textModel.getLineLength(cellLineCount); const cellLastLineEndColumn = cell.textModel.getLineLength(cellLineCount);
const editOperation = { range: new Range(cellLineCount, cellLastLineEndColumn + 1, cellLineCount, cellLastLineEndColumn + 1), text: insertContent };
const editorSelections = cell.getSelections(); await this._bulkEditService.apply(
cell.textModel.applyEdits([editOperation]); [
const inverseRange = PieceTreeTextBuffer._getInverseEditRange(editOperation.range, editOperation.text); new ResourceTextEdit(cell.uri, { range: new Range(cellLineCount, cellLastLineEndColumn + 1, cellLineCount, cellLastLineEndColumn + 1), text: insertContent }),
new ResourceNotebookCellEdit(this._notebook.uri,
await this.deleteCell(index + 1, true, false); {
editType: CellEditType.Replace,
this._undoService.pushElement(new JoinCellEdit( index: index + 1,
this.uri, count: 1,
index + 1, cells: []
direction, }
cell, )
editorSelections, ],
inverseRange, { quotableLabel: 'Join Notebook Cells' }
insertContent,
below,
{
insertCell: (index: number, cell: NotebookCellTextModel, endSelections?: number[]) => {
this.createCell(index, cell.getValue(), cell.language, cell.cellKind, cell.metadata, cell.outputs, true, false);
},
deleteCell: (index: number) => {
this.deleteCell(index, true, false);
},
createCellViewModel: (cell: NotebookCellTextModel) => {
return createCellViewModel(this._instantiationService, this, cell);
}
})
); );
return { cell, deletedCells: [below] }; return { cell, deletedCells: [below] };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册