From 18ac9cad95588cea1f2b999aabee3e2eb03b51f0 Mon Sep 17 00:00:00 2001 From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> Date: Sun, 21 Apr 2024 23:01:39 -0400 Subject: out of bounds dragging fixed indexes --- .../collections/collectionSchema/CollectionSchemaView.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx index 7fcac09dc..3de70ca2c 100644 --- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx +++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx @@ -91,7 +91,7 @@ export class CollectionSchemaView extends CollectionSubView() { @observable _selectedCol: number = 0; @observable _selectedCells: Array = []; @observable _mouseCoordinates = { x: 0, y: 0 }; - @observable _lowestSelectedIndex = -1; + @observable _lowestSelectedIndex = -1; //lowest index among selected rows; used to properly sync dragged docs with cursor position @observable _relCursorIndex = -1; //cursor index relative to the current selected cells // target HTMLelement portal for showing a popup menu to edit cell values. @@ -410,6 +410,12 @@ export class CollectionSchemaView extends CollectionSubView() { return index; }; + /** + * Calculates the relative index of the cursor in the group of selected rows, ie. + * if five rows are selected and the cursor is in the middle row, its relative index would be 2. + * Used to align actively dragged documents properly with the cursor. + * @param mouseY the initial Y position of the cursor on drag + */ @action setRelCursorIndex = (mouseY: number) => { let rowHeight = CollectionSchemaView._rowHeight; @@ -428,6 +434,7 @@ export class CollectionSchemaView extends CollectionSubView() { this._relCursorIndex = index; } + //Uses current mouse position to calculate the indexes of actively dragged docs findRowDropIndex = (mouseY: number) => { let index: number = 0; this.rowHeights.reduce((total, curr, i) => { @@ -437,6 +444,12 @@ export class CollectionSchemaView extends CollectionSubView() { } return total + curr; }, CollectionSchemaView._rowHeight); + + //fix index if selected rows are dragged out of bounds + if (index <= 0) index = 1 + let maxY = this.rowHeights.reduce((total, curr) => total + curr, 0) + CollectionSchemaView._rowHeight; + if (mouseY > maxY) index = this.childDocs.length - 1; + return index - this._relCursorIndex; }; -- cgit v1.2.3-70-g09d2