Sublime Forum

insert_snippet command for view.sel()

#1

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

#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.

0 Likes

#2

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

0 Likes