Home Download Buy Blog Forum Support

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

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

Postby aronwoost on Fri Jul 26, 2013 8:25 pm

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?
aronwoost
 
Posts: 4
Joined: Fri Jul 26, 2013 8:16 pm

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

Postby aronwoost on Sat Jul 27, 2013 10:53 am

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

Example:

Code: Select all
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))


Can someone verify this?
aronwoost
 
Posts: 4
Joined: Fri Jul 26, 2013 8:16 pm

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

Postby tito on Sat Jul 27, 2013 2:20 pm

Sometimes or always, when you use set_timeout, after the command is executed, the self.view or self.window is dereferenced:
Code: Select all
def set_region(self):
    sublime.active_window().active_view().sel().clear()
    sublime.active_window().active_view().sel().add(sublime.Region(self.start, self.end))
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 866
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

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

Postby aronwoost on Sat Jul 27, 2013 7:21 pm

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.
aronwoost
 
Posts: 4
Joined: Fri Jul 26, 2013 8:16 pm

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

Postby makc on Wed Dec 18, 2013 7:32 pm

makc
 
Posts: 8
Joined: Wed Dec 18, 2013 7:22 pm

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

Postby lunixbochs on Thu Dec 19, 2013 2:07 am

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

Code: Select all
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)
lunixbochs
 
Posts: 91
Joined: Fri Oct 08, 2010 10:18 pm


Return to Plugin Development

Who is online

Users browsing this forum: Google [Bot] and 3 guests