visidata
visidata copied to clipboard
[cmdlog] when key column values are not unique, row commands refer to incorrect rows
Small description Whem working on a sheet with a key column that repeats values, row commands will be logged for incorrect rows. The row commands will incorrectly refer to the first row that matched the ambiguous key value, even when they should refer to the second, third, etc.
With a starting sheet of:
key order
repeat 1
repeat 2
repeat 3
Make key
a key column, slide the middle row (repeat, 2
) down 1 row, then undo and redo the command: !
Down
J
U
then R
Expected result
key order
repeat 1
repeat 3
repeat 2
Actual result with screenshot
key order
repeat 2
repeat 1
repeat 3
Steps to reproduce with sample data and a .vd
cmdlog_ambiguous_row.csv
vd cmdlog_ambiguous_row.csv
Additional context visidata v3.1dev
If there are no key columns, everything works as expected. The ambiguous row recording happens here: https://github.com/saulpw/visidata/blob/5772c0f5e817fba2a7a1f9f5949cb959067cebca/visidata/cmdlog.py#L128-L130
Oi, this is tricky. The conflation of the cmdlog and the undo functions might make this hard to untangle. We could just use the row numbers in the cmdlog always, but then replaying a cmdlog becomes more brittle. We could store both in the cmdlog, and use the row number for undo and the key value (if available) when saving the cmdlog. But maybe even that latter case should be based on whether there are duplicate key values.