Skip to content

Commit f6824e9

Browse files
authored
Correctly handle undo with multiple tasks (#3886)
The `std::stringstream::clear` method does not, in fact, clear the string -- it just resets some internal flags. Assigning a new stringstream to the variable is not the most efficient way to do this, but it's the clearest.
1 parent 89d84f0 commit f6824e9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/commands/CmdUndo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ bool CmdUndo::confirm_revert(const std::vector<Operation>& undo_ops) {
102102
view.set(row, 1, mods.str());
103103
}
104104
last_uuid = op.get_uuid();
105-
mods.clear();
105+
mods = std::stringstream();
106106
}
107107

108108
if (op.is_create()) {

test/undo.test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import sys
2929
import os
30+
import re
3031
import unittest
3132

3233
# Ensure python finds the local simpletap module
@@ -61,6 +62,25 @@ def test_add_done_undo(self):
6162
code, out, err = self.t("_get 1.status")
6263
self.assertEqual(out.strip(), "pending")
6364

65+
def test_modify_multiple_tasks(self):
66+
"""'add' then 'done' then 'undo'"""
67+
self.t("add one")
68+
self.t("add two")
69+
self.t("add three")
70+
self.t("rc.bulk=0 1,2,3 modify +sometag")
71+
code, out, err = self.t("undo", input="y\n")
72+
# This undo output should show one tag modification for each task, possibly with some
73+
# modification-time updates if the modifications spanned a second boundary.
74+
self.assertRegex(
75+
out,
76+
"\s+".join(
77+
[
78+
r"""[0-9a-f-]{36} (Update property 'modified' from\s+'[0-9]+' to '[0-9]+'\s+)?Add tag 'sometag'\s+Add property 'tags' with value 'sometag'"""
79+
]
80+
* 3
81+
),
82+
)
83+
6484
def test_undo_en_passant(self):
6585
"""Verify that en-passant changes during undo are an error"""
6686
self.t("add one")

0 commit comments

Comments
 (0)