Is there a way to get the currently visible region?
What I'm trying to do is to filter the current selection so that the selected text that is not currently visible to the user is discarded from the selection.
Search between bookmarks if there is only one selection? Set up search areas.
For the moment, maybe you could make a plugin where you ctrl mouse click the extents as 2 empty selections, then the search as a 3rd full selection.
Sounds good but I don't see anything about bookmarks in the API documentation.
def find_all(view, search, start, end, flags=0):
regions = [sublime.Region(start, start)]
while True:
regions.append(view.find(search, regions[-1].end(), flags))
if not regions[-1] or regions[-1].begin() > end:
break
return regions[1:-1]
class SearchBetweenBookmarks(sublimeplugin.TextCommand):
def run(self, view, args):
if len(view.sel()) == 3:
start, search_sel, end = view.sel()
else:
search_sel = view.sel()[0]
view.runCommand('prevBookmark')
start = view.sel()[0]
view.runCommand('nextBookmark')
end = view.sel()[-1]
search = view.substr(search_sel or view.word(search_sel))
if search == view.substr(view.word(search_sel)):
search = r'\b%s\b' % search
finds = find_all(view, search, start.begin(), end.end())
view.sel().clear()
for sel in [search_sel] + finds:
view.sel().add(sel)
class BookmarkArea(sublimeplugin.TextCommand):
def run(self, view, args):
sels = view.sel()
start = view.sel()[0].begin()
end = view.sel()[-1].end()
sels.clear()
for pos in (start, end):
view.sel().add(sublime.Region(pos, pos))
view.runCommand('toggleBookmark')
view.sel().clear()
sels.add(sublime.Region(start, start))
Users browsing this forum: No registered users and 1 guest