Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soft undo does not work for the same text command called multiple times #2924

Open
evandrocoan opened this issue Aug 11, 2019 · 0 comments

Comments

@evandrocoan
Copy link

commented Aug 11, 2019

Description

  1. Create this keybinding on your user settings

    [
        { "keys": ["alt+d"], "command": "select_highlighted_next_word" },
    ]
    
  2. Create the plugin bug.py

    import sublime
    import sublime_plugin
    
    class SelectHighlightedNextWordCommand(sublime_plugin.TextCommand):
        def run(self, edit):
            view = self.view
            selections = view.sel()
    
            if selections:
                word_regions = view.find_all( 'selections' )
    
                if word_regions:
    
                    for next_word in word_regions:
    
                        if next_word in selections:
                            continue
    
                        selections.add(next_word)
                        view.show(next_word)
                        break

Expected behavior

  1. Open a Sublime Text Vanilla Install
  2. Create the file bug.py and its keybinding
  3. Press Alt+D 3 times
  4. Press Ctrl+U (soft_undo)
  5. Only one selection is undone (unselected)

Actual behavior

  1. Open a Sublime Text Vanilla Install
  2. Create the file bug.py and its keybinding
  3. Press Alt+D 3 times
  4. Press Ctrl+U (soft_undo)
  5. Now, all 3 selections were undone (it is expected for only one selection to be "undone")

Workaround

A fix or workaround for this problem was figured out accidentally by @OdatNurd and @mattst on https://forum.sublimetext.com/t/plugin-soft-undo/40064

If you create the bug.py by using two text commands chained by a sublime.set_timeout(), everything works as expected:

import sublime
import sublime_plugin

class SelectHighlightedNextWordCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        view = self.view
        sublime.set_timeout( lambda: view.run_command( 'select_highlighted_next_word_bug_fixer' ), 0 )

class SelectHighlightedNextWordBugFixerCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        view = self.view
        selections = view.sel()

        if selections:
            word_regions = view.find_all( 'selections' )

            if word_regions:

                for next_word in word_regions:

                    if next_word in selections:
                        continue

                    selections.add(next_word)
                    view.show(next_word)
                    break

Environment

  • Operating system and version:
    • Windows 10 build 15063 x64
    • Resolution 1920x1080
    • dpi_scale 1.0
    • Sublime Text:
    • Build 3207
    • 64 bit

Related threads

  1. https://forum.sublimetext.com/t/plugin-soft-undo/40064
  2. #2087 Commands "soft_undo" and "soft_redo" do not update visualization of dirty flag

evandrocoan added a commit to evandrocoan/HighlightWordsOnSelection that referenced this issue Aug 11, 2019

Fixed soft_undo unselecting all words at once
Soft undo does not work for the same text command called multiple times
SublimeTextIssues/Core#2924
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant
You can’t perform that action at this time.