aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/views/collections/collectionSchema/CollectionSchemaView.tsx15
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;
};