undo
undo copied to clipboard
feat(history/display): better UX
Preface
Currently, I'm using History::display to display the navigation history for my editor, and I find it confusing during branch switching.
Steps to reproduce
For example, say we start with the following tree:
* 1-3 [HEAD] src/position.rs
* 1-2 src/soft_wrap.rs
| * 0-3 src/quickfix_list.rs
| * 0-2 src/context.rs
|/
* 1-1 src/components/editor.rs
* 1-0 [SAVED]
Expected outcome
And when I switched to [0-3], I expect it to display as follows (only [HEAD] is moved):
* 1-3 src/position.rs
* 1-2 src/soft_wrap.rs
| * 0-3 [HEAD] src/quickfix_list.rs
| * 0-2 src/context.rs
|/
* 1-1 src/components/editor.rs
* 1-0 [SAVED]
Actual outcome
However, it surprised me by totally modifying the tree, specifically:
- Making branch
0the main trunk - Renaming entries
1-1and1-0, to0-1and0-0respectively
* 0-3 [HEAD] src/quickfix_list.rs
* 0-2 src/context.rs
| * 1-3 src/position.rs
| * 1-2 src/soft_wrap.rs
|/
* 0-1 src/components/editor.rs
* 0-0 [SAVED]
Hi, History uses the implementation of Record so the current root is stored inside the Record and everything else is stored in the branches. So when you change root to 0, the record is rebuilt with the edits in 0, and the edits in 1 is moved to the branch storage and get 0 as parent. And then the display will just show the rebuilt history as is.
I see. Also, it is possible to display the history in reverse, where the latest entries are at the bottom, like the following?
* 0-0 [SAVED]
* 0-1 src/components/editor.rs
|\
| * 1-2 src/soft_wrap.rs
| * 1-3 src/position.rs
* 0-2 src/context.rs
* 0-3 [HEAD] src/quickfix_list.rs
Or better, is it possible to traverse the tree either post-orderly or pre-orderly?
Reversing it is not supported right now, but maybe it could be added in #27. How would you expect it to look with post- and pre-order traversal?