mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(core) Fix selection of rows after rows are dragged
Summary: After dragging rows up, selection was set incorrectly. Test Plan: Expanded a browser test for dragging rows to check selection, which fails without this fix Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3324
This commit is contained in:
parent
0f4f0d3dad
commit
fa75f60bfd
@ -718,10 +718,12 @@ GridView.prototype.moveColumns = function(oldIndices, newIndex) {
|
||||
var vsfAction = ['BulkUpdateRecord', vsfRowIds, colInfo];
|
||||
var viewFieldsTable = this.gristDoc.docModel.viewFields;
|
||||
var numCols = oldIndices.length;
|
||||
var self = this;
|
||||
viewFieldsTable.sendTableAction(vsfAction).then(function() {
|
||||
self._selectMovedElements(self.cellSelector.col.start, self.cellSelector.col.end,
|
||||
newIndex, numCols, selector.COL);
|
||||
const newPos = newIndex < this.cellSelector.colLower() ? newIndex : newIndex - numCols;
|
||||
viewFieldsTable.sendTableAction(vsfAction).then(() => {
|
||||
this.cursor.fieldIndex(newPos);
|
||||
this.cellSelector.currentSelectType(selector.COL);
|
||||
this.cellSelector.col.start(newPos);
|
||||
this.cellSelector.col.end(newPos + numCols - 1);
|
||||
});
|
||||
};
|
||||
|
||||
@ -736,10 +738,12 @@ GridView.prototype.moveRows = function(oldIndices, newIndex) {
|
||||
var colInfo = { 'manualSort': newPositions };
|
||||
var action = ['BulkUpdateRecord', rowIds, colInfo];
|
||||
var numRows = oldIndices.length;
|
||||
var self = this;
|
||||
this.tableModel.sendTableAction(action).then(function() {
|
||||
self._selectMovedElements(self.cellSelector.row.start, self.cellSelector.row.end,
|
||||
newIndex, numRows, selector.ROW);
|
||||
const newPos = newIndex < this.cellSelector.rowLower() ? newIndex : newIndex - numRows;
|
||||
this.tableModel.sendTableAction(action).then(() => {
|
||||
this.cursor.rowIndex(newPos);
|
||||
this.cellSelector.currentSelectType(selector.ROW);
|
||||
this.cellSelector.row.start(newPos);
|
||||
this.cellSelector.row.end(newPos + numRows - 1);
|
||||
});
|
||||
};
|
||||
|
||||
@ -1497,25 +1501,6 @@ GridView.prototype.dropCols = function() {
|
||||
this._colClickTime = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* After rows/cols in the range start() to end() inclusive are moved to newIndex,
|
||||
* update the start and end observables so that they stay selected after the move.
|
||||
* @param {observable} start - observable denoting the start index of the moved/dropped elements
|
||||
* @param {observable} end - observable denoting the end index of the moved/dropped elements
|
||||
* @param {integer} numEles - number of elements to move
|
||||
* @param {integer} newIndex - new index of the start of the selected range
|
||||
*/
|
||||
GridView.prototype._selectMovedElements = function(start, end, newIndex, numEles, elemType) {
|
||||
console.assert(elemType === selector.ROW || elemType === selector.COL);
|
||||
var newPos = newIndex < Math.min(start(), end()) ? newIndex : newIndex - numEles;
|
||||
if (elemType === selector.COL) this.cursor.fieldIndex(newPos);
|
||||
else if (elemType === selector.ROW) this.cursor.rowIndex(newPos);
|
||||
|
||||
this.cellSelector.currentSelectType(elemType);
|
||||
start(newPos);
|
||||
end(newPos + numEles - 1);
|
||||
};
|
||||
|
||||
// End of Dragging logic
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user