Sublime Forum

How to work with selection?

#1

There is view.sel() but I can’t figure out how to use it. Using the following codes as example, how do you make it work only in selection of text?

class FoobarCommand(sublime_plugin.TextCommand): def run(self, edit): str = self.view.find_all(" foo ") str.reverse() for r in str: self.view.erase(edit, r)

0 Likes

#2

It’s difficult to understand what you are asking. Are you asking how to restrict your find_all searches to selected text? If so, you could just check if each region from find_all is within view.sel() (using the contains method).

0 Likes