diff options
author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-04-21 23:01:39 -0400 |
---|---|---|
committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-04-21 23:01:39 -0400 |
commit | 18ac9cad95588cea1f2b999aabee3e2eb03b51f0 (patch) | |
tree | b7ec4942a9d4db523a0350d91cbbb4d034a7a4c0 | |
parent | 0f3e2be5cf429da12f694121597e94bc56b3e354 (diff) |
out of bounds dragging fixed indexes
-rw-r--r-- | src/client/views/collections/collectionSchema/CollectionSchemaView.tsx | 15 |
1 files changed, 14 insertions, 1 deletions
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<Doc> = []; @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; }; |