diff --git a/CHANGELOG.md b/CHANGELOG.md index ca690b9..5075edc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,12 @@ Repository and `curl | sh` installs only; the PyPI package is unaffected. **Fixed** +- Undo stepped back too far after a run of typing. A run was only ever + recorded as its first keystroke, so the undo point left behind held one + character of what had been typed: entering `KEEP`, pressing enter and + undoing once left `K`. The guard that was meant to keep the state in + sync while an action continued tested `current_state < len(history)-1`, + which is never true while editing forwards. - Pasting indented text produced a staircase, each line indented further than the last. A paste arrives as ordinary keystrokes, so auto indent fired on every newline and prepended the previous line's whitespace to diff --git a/suplemon/editor.py b/suplemon/editor.py index 3c21d42..11d2a05 100644 --- a/suplemon/editor.py +++ b/suplemon/editor.py @@ -119,11 +119,15 @@ def store_action_state(self, action, state=None): if self.last_action != action: self.last_action = action self.store_state(state) - else: - # FIXME: This if is here just for safety. - # FIXME: current_state might be wrong ;.< - if self.current_state < len(self.history)-1: - self.history[self.current_state].store(self) + elif self.current_state > 0: + # Same action continuing, so fold it into the state this run + # already created rather than making a new one. The guard used + # to be current_state < len(history)-1, which is never true + # while editing forwards: store_state leaves current_state at + # the end of the history. So a run was only ever recorded as + # its first keystroke, and the next different action left an + # undo point holding one character of what the user had typed. + self.history[self.current_state].store(self) def store_state(self, state=None, action=None): """Store the current editor state for undo/redo."""