Home Download Buy Blog Forum Support

insert_snippet command for view.sel()

insert_snippet command for view.sel()

Postby atomi on Fri Feb 08, 2013 6:05 am

I noticed this problem and was curious as to why it happens:

Code: Select all
#sublime_plugin.TextCommand
def run(self, edit):
    for region in self.view.sel():
        self.view.run_command('insert_snippet', {'contents': str(region.b)})


if I run this command on multiple cursors via a keybinding Sublime inserts something like:
5813
5813
5813
instead of what self.view.insert(edit, region.b, str(region.b)) would for example:
5
8
13

Does anyone know if this limitation of run_command is intended or could it be considered a bug?
If this is because the code runs asynchronously and run_command executes only after the loop shouldn't this output just the last 'region.b' in this case '13'.
This isn't a blocking problem for me I'm just curious to know how this code is running.
Edit: Thanks.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: insert_snippet command for view.sel()

Postby sublimator on Fri Feb 08, 2013 3:45 pm

`insert_snippet` command is mult select aware itself and inserts the caret point index at EACH selection.

3 x 3 insertions all up

5,5,5
8,8,8
13,13,13

It's definitely not due to async
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 6 guests