mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Reported as "when I try to restore card description from card history, it restores wrong history, that I did not select" - and the selection was never wrong. The server restored exactly the row whose checkbox was ticked. It applied the wrong half of it. A row carries two contents, before and after. The History table shows the AFTER - History.md 7 says the content column holds "the new text" - and Restore applied the BEFORE, because it reused the undo path: `applyRow(row, 'undo')`. So choosing the row that displayed the description you wanted handed you the description from the row above it, and choosing rows one after another walked backwards through the history instead of moving through it. Restore now has a direction of its own. The rule is one sentence: the row a reader picks and the value they get are the same thing. A row with no new content is a removal, so restoring one puts back what it removed. Undo is deliberately the other way round - Ctrl+Z reverses your own last change - and is unchanged. The two only agree when the row you pick happens to be the last one, which is why this survived the first pass: the live check restored a title that WAS the most recent change, so undo and restore gave the same answer. The rule moved into `contentForDirection` in models/lib/changeHistoryGroups.js so it can be tested as arithmetic, with no server and no database, and so applyRow and the restore method cannot drift apart. A restore is itself recorded, and those rows were wrong in the same way: they repeated the restored row's own before/after, which describes a different change. The live value is now read BEFORE the write and recorded as what was displaced, so restoring FIRST over THIRD says so. Verified against a running server: three description versions, FIRST, SECOND, THIRD, with THIRD current. Picking the row showing FIRST set the description to FIRST and logged THIRD -> FIRST; then picking SECOND set it to SECOND and logged FIRST -> SECOND. Before this, picking FIRST emptied the description. tests/historyRestoreAppliesWhatIsShown.test.cjs pins the rule from both ends - what restore applies, and that the table shows that same content - along with removals, additions and junk input. tests/changeHistoryWiring.test.cjs pinned the old inline ternary by its text; it now runs the rule instead, which a move like this cannot break. Thanks to xet7 !