fix (fills ui): Preserve sort order during incremental update
Binary search is used to add, remove, and change rows in response to
incremental updates. Needless to say, if the rows become unsorted,
everything breaks.
Bugs (fixed):
* The fills window crashes sometimes, possibly related to client
reconnecting to server.
Cause: This was a 2 part bug.
1) Changes to existing rows are applied BEFORE the new sort index
is determined via binary search. If the change affects a
property in the current sorting criteria, the rows could
become unsorted and thus invalidate the binary search.
2) When an existing row is changed so that its new sort index is
greater than its current one, the new index is not decremented
by one (it must be since the row is removed before it is
re-inserted).
This commit is contained in:
1 parent
91a7c35edf
commit
eee7af494a
1 file changed
+4
-2
@@ -240,16 +240,18 @@ namespace mbts.ui.utility {
|
||||
wrapped_models.InsertSorted(table.state.Values, comp);
|
||||
return;
|
||||
} else {
|
||||
var view_item = update(target[pos], ch.New);
|
||||
int new_pos = CollectionHelper.binary_search(wrapped_models, ch.New, comp);
|
||||
var view_item_state = update(target[pos], ch.New);
|
||||
if (new_pos < 0)
|
||||
new_pos = ~new_pos;
|
||||
var view_item = update(target[pos], ch.New);
|
||||
if (Math.Abs(new_pos - pos) > 1) {
|
||||
// If the abs diff between old & new positions is 1 (or 0),
|
||||
// the item does not need to be moved because its position wrt the other elements is unchanged.
|
||||
var state = on_moving == null ? default : on_moving(view_item);
|
||||
target.RemoveAt(pos);
|
||||
if (new_pos > pos) {
|
||||
new_pos--;
|
||||
}
|
||||
target.Insert(new_pos, view_item);
|
||||
on_moved?.Invoke(view_item, state);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user