Skip to content

Commit

Permalink
Fix other cells in dragged selection not being grayed out
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Mar 17, 2022
1 parent 6e622ca commit 27e2f3a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface CellViewModelStateChangeEvent {
readonly cellLineNumberChanged?: boolean;
readonly inputCollapsedChanged?: boolean;
readonly outputCollapsedChanged?: boolean;
readonly dragStateChanged?: boolean;
}

export interface NotebookLayoutChangeEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IResolvedTextEditorModel> | undefined;
Expand Down

0 comments on commit 27e2f3a

Please sign in to comment.