everyonesdesign / OpenSearchInNewTab

Plugin for Sublime Text 3 opening each "Find in Folder" result in a new tab
MIT License
7 stars 2 forks source link

the logic of the code #1

Closed stayliv3 closed 9 years ago

stayliv3 commented 9 years ago

everyonesdesign:

hello,i want to use the function in my own plugin, i have the same need for open a new tab for search result .I can not understand your code though it is very simple .can u explain something for me .

thanks.

everyonesdesign commented 9 years ago

@stayliv3 OK, no problem, I'll try to explain it.

Firstly, how sublime search tab opening works (I found out it experimentally):

So I decided to rename the tab to trick the Sublime. I change tab's name to 'Find Results ' (with space as it reads the same by human but it's not the same thing for the editor) on on_activated hook:

def on_activated(self, view):
        if view.name() == DEFAULT_NAME: # DEFAULT_NAME == 'Find Results'
            view.set_name(ALT_NAME) # ALT_NAME == 'Find Results '

That's how it's basically work.

Then I found out that other plugins (in my case it was BetterFindBuffer) also detected search tab by its name so I decided to set back name 'Find Results' on on_text_command hook so the plugins can execute their text command on the correctly named tab; After that execution post_text_command again sets it to name with a space.

I see that it's not 100% reliable but that's the best way I've figured out to do that.

stayliv3 commented 9 years ago

thanks for your kind help.

everyonesdesign commented 9 years ago

@stayliv3 You're welcome!