Skip to content

anonymous /AddFind.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
import sublime, sublime_plugin
class AddFindCommand(sublime_plugin.TextCommand):
def run(self, edit):
self._orig_sel = list(self.view.sel())
self.view.window().show_input_panel('find', '',
self.on_done, self.on_change, self.on_cancel)
def on_done(self, s):
self.view.erase_regions('addfind')
self.expand_sel(s)
def on_change(self, s):
if s != '':
#print(repr(s))
self.show_regions(s)
def on_cancel(self):
pass
def show_regions(self, s):
regs = []
for r in self._orig_sel:
new_begin = r.end()
new_end = self.view.find(s, r.end(), sublime.LITERAL).end()
if not r.empty():
new_begin -= 1
regs.append(sublime.Region(new_begin, new_end))
for r in regs:
self.view.add_regions('addfind', regs, 'comment', flags=sublime.DRAW_OUTLINED)
def expand_sel(self, s):
regs = []
for r in self._orig_sel:
new_begin = r.end()
new_end = self.view.find(s, r.end(), sublime.LITERAL).end()
if not r.empty():
new_begin -= 1
regs.append(sublime.Region(new_begin, new_end))
for r in regs:
self.view.sel().add(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.