提交 c77deed2 编写于 作者: R rebornix

moveCellIdx

上级 3f1206a3
......@@ -241,10 +241,16 @@ export interface INotebookEditor extends IEditor {
moveCellDown(cell: ICellViewModel): Promise<ICellViewModel | null>;
/**
* @deprecated Note that this method doesn't support batch operations, use #moveCellToIdx instead.
* Move a cell above or below another cell
*/
moveCell(cell: ICellViewModel, relativeToCell: ICellViewModel, direction: 'above' | 'below'): Promise<ICellViewModel | null>;
/**
* Move a cell to a specific position
*/
moveCellToIdx(cell: ICellViewModel, index: number): Promise<ICellViewModel | null>;
/**
* Focus the container of a cell (the monaco editor inside is not focused).
*/
......
......@@ -1182,6 +1182,15 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
return this._moveCellToIndex(originalIdx, newIdx);
}
async moveCellToIdx(cell: ICellViewModel, index: number): Promise<ICellViewModel | null> {
if (!this._notebookViewModel!.metadata.editable) {
return null;
}
const originalIdx = this._notebookViewModel!.getCellIndex(cell);
return this._moveCellToIndex(originalIdx, index);
}
private async _moveCellToIndex(index: number, newIdx: number): Promise<ICellViewModel | null> {
if (index === newIdx) {
return null;
......
......@@ -687,10 +687,14 @@ export class CellDragAndDropController extends Disposable {
}
private async moveCells(draggedCells: ICellViewModel[], ontoCell: ICellViewModel, direction: 'above' | 'below') {
const relativeToIndex = this.notebookEditor!.viewModel!.getCellIndex(ontoCell);
const newIdx = direction === 'above' ? relativeToIndex : relativeToIndex + 1;
this.notebookEditor.textModel!.pushStackElement('Move Cells');
for (let i = 0; i < draggedCells.length; i++) {
await this.notebookEditor.moveCell(draggedCells[i], ontoCell, direction);
for (let i = draggedCells.length - 1; i >= 0; i--) {
await this.notebookEditor.moveCellToIdx(draggedCells[i], newIdx);
}
this.notebookEditor.textModel!.pushStackElement('Move Cells');
}
......@@ -699,7 +703,7 @@ export class CellDragAndDropController extends Disposable {
let firstNewCell: ICellViewModel | undefined = undefined;
let firstNewCellState: CellEditState = CellEditState.Preview;
for (let i = 0; i < draggedCells.length; i++) {
const draggedCell = draggedCells[0];
const draggedCell = draggedCells[i];
const newCell = this.notebookEditor.insertNotebookCell(ontoCell, draggedCell.cellKind, direction, draggedCell.getText());
if (newCell && !firstNewCell) {
......
......@@ -95,7 +95,7 @@ export class DeleteCellEdit implements IResourceUndoRedoElement {
export class MoveCellEdit implements IResourceUndoRedoElement {
type: UndoRedoElementType.Resource = UndoRedoElementType.Resource;
label: string = 'Delete Cell';
label: string = 'Move Cell';
constructor(
public resource: URI,
......
......@@ -160,6 +160,10 @@ export class TestNotebookEditor implements INotebookEditor {
throw new Error('Method not implemented.');
}
moveCellToIdx(cell: ICellViewModel, index: number): Promise<ICellViewModel | null> {
throw new Error('Method not implemented.');
}
moveCell(cell: ICellViewModel, relativeToCell: ICellViewModel, direction: 'above' | 'below'): Promise<ICellViewModel | null> {
throw new Error('Method not implemented.');
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册