Live data from Hacker News

Text Editor Data Structures: Rethinking Undo

cdacamar.github.io

21–30 of 84 posts

Re: Text Editor Data Structures: Rethinking Undo

#21
post #11

Emacs undo-tree does everything I need. Emacs also supports undo in region which most editors don't seem to support and wasn't covered by the article. I actually used regular Emacs undo for years which lets you get everywhere in the tree with a kind of tree traversal but you won't know where you are. I resisted undo-tree for ages but it's definitely worth it as it stays out of the way until the occasion you might nee…

Emacs's undo is great in that invoking an undo command is itself undoable. And that is different from just your standard redo. It definitely needs some getting used to but it is very powerful. But I think your second points deserves an even bigger mention: Emacs has the ability to apply undo only to a certain "region" - which in Emacs parlance is basically just a selection of text. For those of you who have never see…

What happens when, for example, you atomically replace “mouse” by “elephant”, then select “epha”, and then region-undo?

The reason most editors don’t implement this is probably that it’s hard to conceive of how it should behave in the general case. (That’s not to say that the way Emacs is implementing it isn’t good and useful.)

Re: Text Editor Data Structures: Rethinking Undo

#22
If you are looking for counter examples, take a look at Excel on windows. It undoes in multiple windows.

Say you have two documents open. You make a change in the first then change the second document then go back to the first and make a change. One document has two changes and the other has one.

First undo impacts document one. Second alters document two. Infuriating

Re: Text Editor Data Structures: Rethinking Undo

#23

Thinking about undo/redo is a great place to start thinking about your text editor's underlying data structure. I went down this rabbit hole a while back. I had to really dig[1]: it's been 5 years... --- Data structures aren't the only interesting rabbit-hole, though. UI/UX doesn't get nearly as much attention as it deserves. There are really only two that I am aware of: Notepad and Vim. Vim's modal editing results i…

Consider my interest piqued. We’ve seen a couple of others in the space, notably Kakoune and Helix. What do you have in mind?

Re: Text Editor Data Structures: Rethinking Undo

#24

Thinking about undo/redo is a great place to start thinking about your text editor's underlying data structure. I went down this rabbit hole a while back. I had to really dig[1]: it's been 5 years... --- Data structures aren't the only interesting rabbit-hole, though. UI/UX doesn't get nearly as much attention as it deserves. There are really only two that I am aware of: Notepad and Vim. Vim's modal editing results i…

I still use a lot of nvi on openbsd. and it has a strange quirk to it's undo.

so "u" undoes your last action. but if you hit it again it undoes the undo, a redo if you will. I did not really think about it much, just accepted that was how nvi worked, a single level undo. But that is not true at all. the trick is you have to "u" undo then "." repeat previous action and you get the full undo stack. and, like the parent post mentioned, you also get a full redo stack the same way. Get it to redo then repeat previous action.

I am not exactly sure what vim does, But I suspect this is one of it's improvements.

Re: Text Editor Data Structures: Rethinking Undo

#25

Reading the comments on how vim and Emacs have implemented Undo/Redo with various options was very helpful. I personally don't use these editors, but I'm working on a graph drawing tool where the user usually modifies multiple parts of the graph. Right now we only have linear redo/undo implemented. Reading about all this other options is really helpful. Especially the Time travel and the regional undo are very smart…

> Time travel and the regional undo

Jetbrains’ IDEs have both of them and more. The feature is called “Local History”. [1] You can see the history of an file, a selected region of text, or even your entire project. It can undo file deletions/moves/renames. It feels like a personal “automated git without the git hassles”. It has got me out of some really bad situations.

[1] https://www.jetbrains.com/help/idea/local-history.html

Re: Text Editor Data Structures: Rethinking Undo

#26
post #22

If you are looking for counter examples, take a look at Excel on windows. It undoes in multiple windows. Say you have two documents open. You make a change in the first then change the second document then go back to the first and make a change. One document has two changes and the other has one. First undo impacts document one. Second alters document two. Infuriating

Yes. This is arguably the most infuriating implementation of undo/redo that I've used in any application.

It's worse than an undo that just wipes-out the document. In that scenario I'd just not use the feature.

The behavior in Excel tricks you into using the feature by working as you'd expect in a single document scenario. Then you open a second document and end up trashing one or the other when you undo the wrong thing.

I don't know how anybody ever thought this implementation was the right answer. Ever.

Re: Text Editor Data Structures: Rethinking Undo

#27
post #24

Thinking about undo/redo is a great place to start thinking about your text editor's underlying data structure. I went down this rabbit hole a while back. I had to really dig[1]: it's been 5 years... --- Data structures aren't the only interesting rabbit-hole, though. UI/UX doesn't get nearly as much attention as it deserves. There are really only two that I am aware of: Notepad and Vim. Vim's modal editing results i…

I still use a lot of nvi on openbsd. and it has a strange quirk to it's undo. so "u" undoes your last action. but if you hit it again it undoes the undo, a redo if you will. I did not really think about it much, just accepted that was how nvi worked, a single level undo. But that is not true at all. the trick is you have to "u" undo then "." repeat previous action and you get the full undo stack. and, like the parent…

Yes, in Vim, repeated u's just continues undoing, while ctrl-r is for redos.

Re: Text Editor Data Structures: Rethinking Undo

#28
post #24

Thinking about undo/redo is a great place to start thinking about your text editor's underlying data structure. I went down this rabbit hole a while back. I had to really dig[1]: it's been 5 years... --- Data structures aren't the only interesting rabbit-hole, though. UI/UX doesn't get nearly as much attention as it deserves. There are really only two that I am aware of: Notepad and Vim. Vim's modal editing results i…

I still use a lot of nvi on openbsd. and it has a strange quirk to it's undo. so "u" undoes your last action. but if you hit it again it undoes the undo, a redo if you will. I did not really think about it much, just accepted that was how nvi worked, a single level undo. But that is not true at all. the trick is you have to "u" undo then "." repeat previous action and you get the full undo stack. and, like the parent…

With vim, "u" always moves back in time through the undo history, CTRL-r forward. "." repeats the last action which changed some text but not stuff like moves or going forward/backward through the undo history.

nvi sounds very weird to me.

Re: Text Editor Data Structures: Rethinking Undo

#29

Thinking about undo/redo is a great place to start thinking about your text editor's underlying data structure. I went down this rabbit hole a while back. I had to really dig[1]: it's been 5 years... --- Data structures aren't the only interesting rabbit-hole, though. UI/UX doesn't get nearly as much attention as it deserves. There are really only two that I am aware of: Notepad and Vim. Vim's modal editing results i…

> Vim's modal editing results in the user explicitly defining undo/redo points.

? How? Does switching to normal mode create an undo/redo point? Someone asked me if the granularity of Vim's undo/redo could be increased (i.e., more frequent undo/redo points). In what they demonstrated, Vim's granularity seemed less than other applications (i.e., undo/redo acted on relatively large chunks of input); in some brief research, I didn't find a solution.

Re: Text Editor Data Structures: Rethinking Undo

#30

Thinking about undo/redo is a great place to start thinking about your text editor's underlying data structure. I went down this rabbit hole a while back. I had to really dig[1]: it's been 5 years... --- Data structures aren't the only interesting rabbit-hole, though. UI/UX doesn't get nearly as much attention as it deserves. There are really only two that I am aware of: Notepad and Vim. Vim's modal editing results i…

I'm working on a new modal editor. There's a demo on steam. It's definitely not a vi clone. https://store.steampowered.com/app/1537490/Tentacle_Typer/
Post reply on HN