undo icon indicating copy to clipboard operation
undo copied to clipboard

feat(history/display): better UX

Open wongjiahau opened this issue 2 years ago • 3 comments

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:

  1. Making branch 0 the main trunk
  2. Renaming entries 1-1 and 1-0, to 0-1 and 0-0 respectively
* 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]

wongjiahau avatar Oct 27 '23 04:10 wongjiahau

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.

evenorog avatar Oct 27 '23 07:10 evenorog

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?

wongjiahau avatar Oct 27 '23 07:10 wongjiahau

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?

evenorog avatar Oct 27 '23 11:10 evenorog