Sublime Forum

ST2 & ST3: View is not updated after adding new Region

#1

I’ve created a little TextCommand plugin, that adds a new Region. However, when the Region is added the view does not display the updated selection, although it displays in the status bar how many character are selected. Also when I change to another tab and get back to the original one, the correct text selection is displayed.

How to I force a redraw?

Note: This solution doesn’t do anything. This solution works, however since it reloads the view flickers for a tiny second (not nice).

Any ideas?

1 Like

#2

After further investigation it seams to have something to do with set_timeout.

Example:

[code]import sublime, sublime_plugin

class Example1Command(sublime_plugin.TextCommand):
def run(self, edit):

self.start = 0
self.end = 500

# this works
# self.set_region()

sublime.set_timeout(lambda: self.set_region(), 1)

def set_region(self):
self.view.sel().clear()
self.view.sel().add(sublime.Region(self.start, self.end))[/code]

Can someone verify this?

0 Likes

#3

Sometimes or always, when you use set_timeout, after the command is executed, the self.view or self.window is dereferenced:

def set_region(self): sublime.active_window().active_view().sel().clear() sublime.active_window().active_view().sel().add(sublime.Region(self.start, self.end))

0 Likes

#4

Well, in this case it’s not. Everything works as expected, only the view is not updated (like described in first post). Anyways, thanks for looking into it.

0 Likes

#5

I have found another workaround for this issue.

0 Likes

#6

I had better success running view/region/cursor/status updates in a TextCommand. You can use my Edit class to automate this: github.com/lunixbochs/actualvim … er/edit.py

from .edit import Edit

# one way to do it
Edit.defer(view, lambda: do something)

# another way, which you can mix with edit.insert() etc and it will apply everything at once
with Edit(View) as edit:
    edit.callback(lambda: do something)
0 Likes

Running "goto_row_col" command in custom plugin