diff --git a/src/vs/workbench/contrib/notebook/browser/notebookViewEvents.ts b/src/vs/workbench/contrib/notebook/browser/notebookViewEvents.ts index 785c4e5998f56..15b684b1760d7 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookViewEvents.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookViewEvents.ts @@ -29,6 +29,7 @@ export interface CellViewModelStateChangeEvent { readonly cellLineNumberChanged?: boolean; readonly inputCollapsedChanged?: boolean; readonly outputCollapsedChanged?: boolean; + readonly dragStateChanged?: boolean; } export interface NotebookLayoutChangeEvent { diff --git a/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellDnd.ts b/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellDnd.ts index 369d267c9817a..6badf82db57ab 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellDnd.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellDnd.ts @@ -8,6 +8,7 @@ import { Delayer } from 'vs/base/common/async'; import { Disposable, MutableDisposable } from 'vs/base/common/lifecycle'; import * as platform from 'vs/base/common/platform'; import { expandCellRangesWithHiddenCells, ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; +import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents'; import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellPart'; import { BaseCellRenderTemplate, INotebookCellList } from 'vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon'; import { cloneNotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel'; @@ -37,18 +38,25 @@ export class CellDragAndDropPart extends CellPart { } override didRenderCell(element: ICellViewModel): void { - if (element.dragging) { - this.container.classList.add(DRAGGING_CLASS); - } else { - this.container.classList.remove(DRAGGING_CLASS); + this.update(element); + } + + override updateState(element: ICellViewModel, e: CellViewModelStateChangeEvent): void { + if (e.dragStateChanged) { + this.update(element); } } + + private update(element: ICellViewModel) { + this.container.classList.toggle(DRAGGING_CLASS, element.dragging); + } } export class CellDragAndDropController extends Disposable { // TODO@roblourens - should probably use dataTransfer here, but any dataTransfer set makes the editor think I am dropping a file, need // to figure out how to prevent that private currentDraggedCell: ICellViewModel | undefined; + private draggedCells: ICellViewModel[] = []; private listInsertionIndicator: HTMLElement; @@ -278,8 +286,9 @@ export class CellDragAndDropController extends Disposable { private dragCleanup(): void { if (this.currentDraggedCell) { - this.currentDraggedCell.dragging = false; + this.draggedCells.forEach(cell => cell.dragging = false); this.currentDraggedCell = undefined; + this.draggedCells = []; } this.setInsertIndicatorVisibility(false); @@ -314,14 +323,13 @@ export class CellDragAndDropController extends Disposable { } this.currentDraggedCell = templateData.currentRenderedCell!; - this.currentDraggedCell.dragging = true; + this.draggedCells = this.notebookEditor.getSelections().map(range => this.notebookEditor.getCellsInRange(range)).flat(); + this.draggedCells.forEach(cell => cell.dragging = true); const dragImage = dragImageProvider(); cellRoot.parentElement!.appendChild(dragImage); event.dataTransfer.setDragImage(dragImage, 0, 0); setTimeout(() => cellRoot.parentElement!.removeChild(dragImage!), 0); // Comment this out to debug drag image layout - - container.classList.add(DRAGGING_CLASS); }; for (const dragHandle of dragHandles) { templateData.templateDisposables.add(DOM.addDisposableListener(dragHandle, DOM.EventType.DRAG_START, onDragStart)); diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts index a5f73d4c62679..da35868b32717 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts @@ -70,22 +70,6 @@ export abstract class BaseCellViewModel extends Disposable { private _editState: CellEditState = CellEditState.Preview; - // get editState(): CellEditState { - // return this._editState; - // } - - // set editState(newState: CellEditState) { - // if (newState === this._editState) { - // return; - // } - - // this._editState = newState; - // this._onDidChangeState.fire({ editStateChanged: true }); - // if (this._editState === CellEditState.Preview) { - // this.focusMode = CellFocusMode.Container; - // } - // } - private _lineNumbers: 'on' | 'off' | 'inherit' = 'inherit'; get lineNumbers(): 'on' | 'off' | 'inherit' { return this._lineNumbers; @@ -149,6 +133,7 @@ export abstract class BaseCellViewModel extends Disposable { set dragging(v: boolean) { this._dragging = v; + this._onDidChangeState.fire({ dragStateChanged: true }); } protected _textModelRef: IReference | undefined;