Sublime Forum

Little help with show_input_panel

#1

Hi guys. So, i have this small plugin that replace # chars with numbers. The problem is that it never worked on ST3 and today i decided to allocate some time to fix it.

Here is the full code: gist.github.com/iamntz/5546478

So, when i run the command, i get this error raised:

ValueError: Edit objects may not be used after the TextCommand's run method has returned

There is some weird issue on this code:

window.show_input_panel('Count Start:Step', '1:1', countThoseSelections, False, False)

Because if i eliminate that and i just call the countThoseSelections(‘1:1’) method it just works. Also, params is sent to this method by show_input_panel.

I’m kinda out of ideas. Any help would be appreciated. Thanks!

0 Likes

#2

You lose the edit object when the command returns. You will have to call another command to perform the actual insert. You can use something like

class BatchReplaceCommand(sublime_plugin.TextCommand): def run(self, edit, replace_text, begin_region_point, end_region_point): self.view.replace(edit, region, sublime.Region(begin_region_point, end_region_point))

I didn’t test that, so you may need to modify it a bit to get it work, but you should be able to get your plugin running.

0 Likes