Sublime Forum

MarkFromFindpanel - Bookmark lines from find panel

#1

If you have many search results, then to bookmark them all is super handy so that you can process them one-by-one.

To use plugin: When Find Panel is open, push Alt+Insert from Find Panel to add bookmarks to matching search results. After that you can use the hotkeys for “prev_bookmark” (Alt+PageUp) and “next_bookmark” (Alt+PageDown) to navigate through your search results. And then you can use the hotkey for “toggle_bookmark_wholeline” (Alt+Insert) to toggle all bookmarks on current line or “clear_bookmarks” (Alt+Delete) to clear all bookmarks.

This differs from MarkLinesContaining because it does not make its own input panel but rather re-uses the existing Find panel.

Add to Key Bindings:

[code]{ “keys”: “alt+insert”], “command”: “toggle_bookmark_wholeline” },
{ “keys”: “alt+delete”], “command”: “clear_bookmarks” },
{ “keys”: “alt+pageup”], “command”: “prev_bookmark” },
{ “keys”: “alt+pagedown”], “command”: “next_bookmark” },

{ “keys”: “alt+insert”], “command”: “mark_from_findpanel”, “context”:
{“key”: “panel”, “operand”: “find”}, {“key”: “panel_has_focus”}]
},
{ “keys”: “alt+delete”], “command”: “clearbookmarks_from_findpanel”, “context”:
{“key”: “panel”, “operand”: “find”}, {“key”: “panel_has_focus”}]
},[/code]
Create Plugin mark_from_findpanel.py:

[code]import sublime, sublime_plugin

class MarkFromFindpanelCommand(sublime_plugin.TextCommand):
def run(self, edit):
SearchTerm = self.view.substr(self.view.full_line(0))
ExistingBookmarks = sublime.active_window().active_view().get_regions(“bookmarks”)
# sublime.active_window().active_view().erase_regions(“bookmarks”)
# sublime.active_window().active_view().erase_regions(“mark”)
# self.view.run_command(“clear_bookmarks”)
RegionsResult = ExistingBookmarks + sublime.active_window().active_view().find_all(SearchTerm, sublime.IGNORECASE | sublime.LITERAL)
# sublime.active_window().active_view().add_regions(“bookmarks”, RegionsResult, “bookmarks”, “bookmark”, sublime.DRAW_OUTLINED | sublime.PERSISTENT) # valid gutter icons are dot, circle, bookmark and cross
sublime.active_window().active_view().add_regions(“bookmarks”, RegionsResult, “bookmarks”, “bookmark”, sublime.HIDDEN | sublime.PERSISTENT) # valid gutter icons are dot, circle, bookmark and cross
sublime.active_window().run_command(‘hide_panel’)

class ClearbookmarksFromFindpanelCommand(sublime_plugin.TextCommand):
def run(self, edit):
# self.view.run_command(‘clear_bookmarks’)
sublime.active_window().active_view().run_command(‘clear_bookmarks’)

class ToggleBookmarkWholelineCommand(sublime_plugin.TextCommand):
def run(self, edit):
caretLine = self.view.line(self.view.sel()[0])
oldBookmarks = self.view.get_regions(“bookmarks”)
newBookmarks = ]
bookmarkFoundOnCaretLine = False
for thisbookmark in oldBookmarks:
# if thisbookmark.intersects(caretLine):
if ( (thisbookmark.begin() >= caretLine.begin()) and (thisbookmark.begin() <= caretLine.end()) or
(thisbookmark.end() >= caretLine.begin()) and (thisbookmark.end() <= caretLine.end()) ):
bookmarkFoundOnCaretLine = True
else:
newBookmarks.append(thisbookmark)
if not bookmarkFoundOnCaretLine:
newBookmarks.append(self.view.sel()[0])
sublime.active_window().active_view().add_regions(“bookmarks”, newBookmarks, “bookmarks”, “bookmark”, sublime.HIDDEN | sublime.PERSISTENT)
[/code]

0 Likes

MarkLinesContaining - Bookmark lines from custom panel
What plugin to use for bookmarks?
Best way to block bookmarking?