Live data from Hacker News

Text Editor Data Structures: Rethinking Undo

cdacamar.github.io

31–40 of 84 posts

Re: Text Editor Data Structures: Rethinking Undo

#31
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…

I can't believe that, in 16 minutes, nobody else on HN had the answer: nvi is following original, authentic vi behavior, not this newfangled stuff. The Vim manual explains it:

  How undo and redo commands work depends on the 'u' flag in 'cpoptions'.
  There is the Vim way ('u' excluded) and the Vi-compatible way ('u' included).
  In the Vim way, "uu" undoes two changes.  In the Vi-compatible way, "uu" does
  nothing (undoes an undo).

  'u' excluded, the Vim way:
  You can go back in time with the undo command.  You can then go forward again
  with the redo command.  If you make a new change after the undo command,
  the redo will not be possible anymore.

  'u' included, the Vi-compatible way:
  The undo command undoes the previous change, and also the previous undo
  command.  The redo command repeats the previous undo command.  It does NOT
  repeat a change command, use "." for that.
https://vimhelp.org/undo.txt.html

(Actually, I have so rarely used vi that I'm relying on the implications of the Vim manual that it's original vi behavior.)

Re: Text Editor Data Structures: Rethinking Undo

#32
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 th…

more interesting part is, when you find these are shared in powerpoint and word, too.

there is not warning about I modified another file, if I dare to work on multiple task, everything probably wreck.

Re: Text Editor Data Structures: Rethinking Undo

#33

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 resear…

There’s a trick to remap space to automatically insert an undo point in vim: https://stackoverflow.com/a/4360415/13099

But, after getting used to vim’s commands, I find I go back to normal mode relatively quickly and so my undo steps are generally logical.

Re: Text Editor Data Structures: Rethinking Undo

#34

I just skimmed it, but it looks like vim really has undo/redo "solved": - Modal editing makes for nice "undo" points, clarifying whether undo should undo "World!" or "!". - "g-" and "g+" eliminate the "orphaned redo". They walk the entire undo/redo tree rather than just the linear undo/redo. - Time travel undo/redo is really handy when you want to go to where you were on the wall-clock. ":earlier 15 minutes" takes yo…

> ":earlier 15 minutes" takes you to the code as it was 15 minutes ago. TIL. Very cool. tnx

Been using vim for few years, never hears of that feature. Still a student.

Re: Text Editor Data Structures: Rethinking Undo

#35

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 am currently working on an editor. Definitely interesting to try different ideas just to find out why certain things in Vim are that way. Also the "." key is more complicated than I expected, the exact start of an edit operation depends on the behaviour of certain default keybindings. It just works so smoothly I had never thought much about it before.

> Maybe one of these days I will get far enough past the ADHD wall to make it happen...

That's definitely the most difficult part, for me it got easier at some point once it actually seemed realistic that I'd manage to finish it one day.

Re: Text Editor Data Structures: Rethinking Undo

#36
Maya's C++ API was what taught me the most about the importance of proper do/undo functionality. As soon as you start to modify the DAG, you really must ensure that the undo operation leaves everything (be it meshes or shaders or curves, whatever) as it was before your custom object got inserted into the DAG. Else your plugin is worthless.

See the doIt/undoIt methods in https://help.autodesk.com/view/MAYAUL/2022/ENU/?guid=Maya_SD...

Re: Text Editor Data Structures: Rethinking Undo

#37
Both Ardour and Cubase (both DAWs) had branching undo/redo systems in the mid-2000s. Ardour and I think also Cubase abandoned it before 2010 because almost all users could not deal with the complexity.

Maybe for programmer-oriented text editors the user reaction/experience might be different.

Re: Text Editor Data Structures: Rethinking Undo

#38
I used an editor with a redo tree, DeScribe (I believe) word processor on OS/2 and Windows. The redo tree was pretty cool, but I'm so used to losing my stuff on change after undo that I don't miss it. If I really cared to save a version, I would've committed it to my local git.

Re: Text Editor Data Structures: Rethinking Undo

#39

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 resear…

Simply stated, 'u' in vim undoes every change since the last insert.

I suppose for some, "more granular" undo points could be useful, but I'm in such a habit of doing something discrete and then escaping insert mode, that I've never felt pinched by the potential for vim's large undos.

Re: Text Editor Data Structures: Rethinking Undo

#40
post #36

Maya's C++ API was what taught me the most about the importance of proper do/undo functionality. As soon as you start to modify the DAG, you really must ensure that the undo operation leaves everything (be it meshes or shaders or curves, whatever) as it was before your custom object got inserted into the DAG. Else your plugin is worthless. See the doIt/undoIt methods in https://help.autodesk.com/view/MAYAUL/2022/ENU/…

Man, fonts sometimes really matter.

I've been pondering about calling your developers nasty names and what a dolt method is actually doing ...

Until I realized that they were DO-IT, UNDO-IT.

Post reply on HN