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
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:
instead of what self.view.insert(edit, region.b, str(region.b)) would for example:

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.
Posts: 345
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


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
Posts: 645
Joined: Thu Mar 20, 2008 5:41 am

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 7 guests