3 ms·
In 2016 I was frustrated by vscode vim mode undo/redo stack: when you activated undo it would process each individual character insertion/deletion event in sequ
by infogulch 2y ago
In 2016 I was frustrated by vscode vim mode undo/redo stack: when you activated undo it would process each individual character insertion/deletion event in sequence exactly as you typed it, e.g. if you type and delete the same character 100 times it would replay that exact sequence even if it was all one logical INSERT. Replay speed was slow enough (maybe 15-20 changes per second?) that it was excruciating to use.
So I rewrote it and added logic to merge adjacent changes [1] which helped immensely, enough that undo/redo felt instant again. It looks like the core merging logic was rewritten a few years ago [2] (which caused a regression, is imo less readable, and removed useful comments -_-) but the basic idea is still there today.
[1]: https://github.com/VSCodeVim/Vim/commit/0576f199cb7a765efb3cd7a7828fd19ff3af094b#diff-4f43ed31c28406a288f2c26932c9827db19761ce9449e7d6c24b2339b19a3080R100-R140 https://github.com/VSCodeVim/Vim/commit/0576f199cb7a765efb3c...
[2]: https://github.com/VSCodeVim/Vim/blame/v1.29.0/src/history/historyTracker.ts#L156-L201 https://github.com/VSCodeVim/Vim/blame/v1.29.0/src/history/h...
- opello 2y agoAnd it looks like "the most beautiful possible" `let [current, ...rest] = changes` [1] never happened either! [1] https://github.com/VSCodeVim/Vim/pull/496#issuecomment-235476908 https://github.com/VSCodeVim/Vim/pull/496#issuecomment-23547...
- infogulch 2y agoTrue! I didn't even remember that detail. To respond to that comment nearly a decade later, I might object that swapping a zero copy zero allocations iterator for something that does O(N^2) element copies and allocates N new lists for zero practical benefit cannot be beautiful on principle, regardless of how pretty it looks on the surface. Beauty is when practicality and perception pull in parallel towards purpose. Sacrificing one for the other can have a certain aesthetic quality, but I would not call it beautiful.