提交 348a4ce2 编写于 作者: R Rob Lourens

Fix cell drop indicator position, and moving cell when dropping over itself

上级 3f15af11
......@@ -464,12 +464,6 @@
cursor: pointer;
}
.monaco-workbench .notebookOverlay .monaco-list .monaco-list-row:hover .cell-focus-indicator,
.monaco-workbench .notebookOverlay .monaco-list .monaco-list-row.cell-output-hover .cell-focus-indicator,
.monaco-workbench .notebookOverlay .monaco-list .monaco-list-row.focused .cell-focus-indicator {
opacity: 1;
}
.monaco-workbench .notebookOverlay .monaco-list-row .cell-editor-part:before {
z-index: 20;
content: "";
......
......@@ -1200,7 +1200,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
return null;
}
const newIdx = index + 1;
const newIdx = index + 2; // This is the adjustment for the index before the cell has been "removed" from its original index
return this._moveCellToIndex(index, newIdx);
}
......@@ -1231,10 +1231,6 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
const relativeToIndex = this._notebookViewModel!.getCellIndex(relativeToCell);
let newIdx = direction === 'above' ? relativeToIndex : relativeToIndex + 1;
if (originalIdx < newIdx) {
newIdx--;
}
return this._moveCellToIndex(originalIdx, newIdx);
}
......@@ -1247,7 +1243,17 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
return this._moveCellToIndex(originalIdx, index);
}
/**
* @param index The current index of the cell
* @param newIdx The desired index, in an index scheme for the state of the tree before the current cell has been "removed".
* @example to move the cell from index 0 down one spot, call with (0, 2)
*/
private async _moveCellToIndex(index: number, newIdx: number): Promise<ICellViewModel | null> {
if (index < newIdx) {
// The cell is moving "down", it will free up one index spot and consume a new one
newIdx--;
}
if (index === newIdx) {
return null;
}
......
......@@ -622,9 +622,9 @@ export class CellDragAndDropController extends Disposable {
const dropDirection = this.getDropInsertDirection(event);
const insertionIndicatorAbsolutePos = dropDirection === 'above' ? event.cellTop : event.cellTop + event.cellHeight;
const insertionIndicatorTop = insertionIndicatorAbsolutePos - this.list.scrollTop;
const insertionIndicatorTop = insertionIndicatorAbsolutePos - this.list.scrollTop + BOTTOM_CELL_TOOLBAR_HEIGHT / 2;
if (insertionIndicatorTop >= 0) {
this.listInsertionIndicator.style.top = `${insertionIndicatorAbsolutePos - this.list.scrollTop}px`;
this.listInsertionIndicator.style.top = `${insertionIndicatorTop}px`;
this.setInsertIndicatorVisibility(true);
} else {
this.setInsertIndicatorVisibility(false);
......@@ -637,6 +637,11 @@ export class CellDragAndDropController extends Disposable {
private onCellDrop(event: CellDragEvent): void {
const draggedCell = this.currentDraggedCell!;
if (this.isScrolling || this.currentDraggedCell === event.draggedOverCell) {
return;
}
let draggedCells: ICellViewModel[] = [draggedCell];
if (draggedCell.cellKind === CellKind.Markdown) {
......@@ -655,7 +660,7 @@ export class CellDragAndDropController extends Disposable {
const dropDirection = this.getDropInsertDirection(event);
const insertionIndicatorAbsolutePos = dropDirection === 'above' ? event.cellTop : event.cellTop + event.cellHeight;
const insertionIndicatorTop = insertionIndicatorAbsolutePos - this.list.scrollTop;
const insertionIndicatorTop = insertionIndicatorAbsolutePos - this.list.scrollTop + BOTTOM_CELL_TOOLBAR_HEIGHT / 2;
const editorHeight = this.notebookEditor.getDomNode().getBoundingClientRect().height;
if (insertionIndicatorTop < 0 || insertionIndicatorTop > editorHeight) {
// Ignore drop, insertion point is off-screen
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册