Sublime Forum

Soft undo (Ctrl + U) not working with multi-line selection

#1

Hi, there,

Reading the documentation I learn that soft_undo should step back if I select too many lines with select_lines (Ctrl+Alt+Down). However, it just drops the selection of all lines and leaves a single cursor at the original line. There are no key-binding conflicts, since if I enable command logging in the console, I see that it is the soft_undo command which is triggered, not something else. Besides, soft_undo does work with find_under_expand (Quick Add Next) - if I select too many words with Ctrl+D, pressing Ctrl+U makes a step back. Using ST build 3207. Tested both under Ubuntu 18.04 and Windows 10 - the behavior is the same.

0 Likes

#2

Cursor movements (including select_lines) are grouped by time lapse.
If you move the cursor multiple time in the same direction during this time lapse (1 or 2 seconds), ST treat all the movement as a single operation.
When you trigger undo, ST undo the whole group.
To see it in action try to wait 2 seconds after each Ctrl+Alt+Down and try soft_undo after.

I don’t think there’s something you can do to change this behavior, except writing your own plugin to replace select_line command.

0 Likes

#3

Indeed! Thanks for replying, I never noticed this time-lapse behavior (probably because normally I never make 2-second pauses between selecting :slight_smile: ) Is it mentioned anywhere in the documentation (either official or nonofficial)? And why time-lapse does not apply when selecting words with Ctrl+D?

0 Likes

#4

Don’t remember how I found it, and only core dev can explain why select_lines work this way (not sure myself if it’s a good or bad thing).

I think this plugin can works, but it’s not really a supported API so I suppose it can break anytime:

import sublime
import sublime_plugin

class SelectLinesCustomCommand(sublime_plugin.TextCommand):
    def run(self, edit, **kwargs):
        # Start a new undo group
        token = edit.edit_token
        self.view.end_edit(edit)
        subedit = self.view.begin_edit(token, self.name())
        try:
            self.view.run_command("select_lines", kwargs)
        finally:
            self.view.end_edit(subedit)        

And override the default keybinding:

{ "keys": ["ctrl+alt+up"], "command": "select_lines_custom", "args": {"forward": false} },
{ "keys": ["ctrl+alt+down"], "command": "select_lines_custom", "args": {"forward": true} },
1 Like

#5

Thanks again, this seems to fix the problem. I hope ST developers will comment on this issue - I find it to be a bug (why would anyone make pauses between selecting lines, and also official documentation does not imply such behavior at all).

0 Likes