Anyone know the algorithm macOS uses to trigger Undo typing?

Discussion in 'macOS' started by Yr Blues, Apr 16, 2019.

  1. Yr Blues macrumors 68020

    Joined:
    Jan 14, 2008
    #1
    Sometimes I'm typing a long thing and mess up then hit Undo (command-Z) and it takes me really far back, like several paragraphs. Sometimes it Undos just a few words. What are the parameters that it is making for Undo instances?
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    Location:
    betwixt
    #2
    The undoable text sequence is the longest string of uninterrupted keystrokes that produce text.

    An "interruption" in the undoable keystroke sequence is any event that moves the text cursor position to a place other than where the last keystroke was appended, or a cmd-keystroke event that triggers an action, such as ⌘Z.

    Examples of keystrokes that will interrupt an undoable keystroke sequence:
    - arrow keys followed by any editing (addition or removal of text)
    - ⌘Z (Undo) or ⌘V (Paste)
    - most menu actions like ⌘S (Save)

    Examples of non-keystroke events what WON'T interrupt an undoable keystroke sequence:
    - click a menu, then click off it without choosing any menu action.
    - cmd-click a window title-bar to drag it without activating it.

    The examples are not exhaustive lists. I may be mistaken on some examples, or it may depend on OS version.
     
  3. Gregg2 macrumors 603

    Joined:
    May 22, 2008
    Location:
    Milwaukee, WI
    #3
    backspace, backspace !
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    Location:
    betwixt
    #4
    Also, SHIFT+OPTION+left-arrow will select the entire word to the left of the cursor. This can be repeated to select multiple words.Then press BACKSPACE.

    And SHIFT+CMD+left-arrow will select the entire previous line.
     
  5. Yr Blues thread starter macrumors 68020

    Joined:
    Jan 14, 2008
    #5
    Where did you this? Great stuff.
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    Location:
    betwixt
    #6
    I write software. It's pretty much how any Undo logic will work if it coalesces like operations.

    For example, if the Undo buffer is empty (nothing to undo) and a keystroke is received, then it goes into the document at the current text-cursor position, and it goes into the Undo buffer (i.e. that keystroke can now be undone). The next keystroke comes in, so it's appended to the document and to the Undo buffer. The Undo manager sees the prior event is a text keystroke, so it coalesces the two events into a single string. Repeat for more keystrokes.

    If an event comes in that moves the cursor, then that ends the coalescing of like operations (text keystrokes), and begins a new undoable sequence at the new cursor location.

    That's the simplified logic, because reality is always more complicated, but it's the gist of it.
     
  7. Jyby macrumors 6502

    Joined:
    May 31, 2011
    #7
    Keystrokes are just one category of overall "commands"... Which include other user actions that are added to an undo buffer... Undoing these just restores the state of whatever is being tracked in the app... Implementations are probably more complicated than the memento pattern, but the fundamental idea is basically that or generic App wide undo.
     

Share This Page

6 April 16, 2019