4 ms·
I'm writing an editor. Could you explain to me the use case? I looked it up and I don't exactly understand the reason besides it might be fun to look at I real
by levodelellis 1y ago
I'm writing an editor. Could you explain to me the use case? I looked it up and I don't exactly understand the reason besides it might be fun to look at
I really did not like that other editors would lose text if you pressed undo and type. The way my undo's work is if you type "a b c" and hit undo twice (so it's just "a") then type "d", then undo twice, it'll restore to "a b c"
- HexDecOctBin 1y agoMany times, I write a bunch of code before realising that a lot of it (but not all of it) is incorrect. At this point, being able to switch between two different points of history and selectively copy-paste the stuff that was correct is a godsend. This is especially useful if you undid some operations, typed a little and then realised that you forgot to copy some important stuff that was strewn around in the old version.
- levodelellis 1y agoThat's one reason why I implemented it so it wouldn't lose information. Hmm. I plan to implement a diff. The way I have it, you could copy the current source, hit undo to a version you want to compare again than use the clipboard as the version to diff with (vscode calls this "Compare Active File with Clipboard".) If you mess up you can still hit undo to go through all the previous edits you made since it's not lossy. Would this be as good for your usecase?
- HexDecOctBin 1y agoA tree is essentially a nice GUI on top of what you already have. It's allows me to visually click (or navigate) to a specific point of history, instead of remembering to hit Undo 15 times.
- ahartmetz 1y agoAFAIU, it also allows you to redo, even if you accidentally added a letter after undoing. That accidental edit then adds a branch to the tree instead of replacing all the redo entries.
- levodelellis 1y agoJust a thought, do you want it as a tree? It seems like it'd make more sense if there was a bar or key you can press to go back and forward to the changes you want. I didn't really understand why having it as a tree was helpful. I'm not going to say I wont implement it, I'm just saying I'm not understanding why you want it that specific way. Is the change you want always many minutes apart and why you want it as a tree? To find the one that happened many minutes before another? I know some people like how vscode has a timeline that says how many minutes/hours ago a change was, so they can pick it out
- HexDecOctBin 1y agoI type "A B C D". Then I undo thrice to get "A". Then I type to get "A E". And now I realise that what I actually want is "A E B D". My edits have created a branch is history. And I need to switch to the old branch and copy stuff twice (first "B" then "D"). That is why a tree is important.
- levodelellis 1y agoI didn't heavily use undo trees so I don't remember how neovim/emacs displays it. I think I get it enough that if I try it out I'll be able to understand what you mean
- bradrn 1y agoIf I understand correctly, this is the same as the default behaviour for Emacs (on top of which Undo Tree is implemented).