Created
March 10, 2021 23:34
-
-
Save OdatNurd/891fbfa357f18198831b51efaa1c2ee5 to your computer and use it in GitHub Desktop.
Sublime Text 3 bookmark hover toggle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime | |
import sublime_plugin | |
class BookmarkEventListener(sublime_plugin.EventListener): | |
def toggle_bookmarks(self, view, point): | |
# Get existing bookmarks and create a region for the new one | |
bookmarks = view.get_regions("bookmarks") | |
new = sublime.Region(point) | |
# Update the bookmarks list to add or remove this region as needed | |
if new not in bookmarks: | |
bookmarks.append(new) | |
else: | |
del bookmarks[bookmarks.index(new)] | |
# Update the bookmarks and hide the popup | |
view.add_regions("bookmarks", bookmarks, "bookmarks", "bookmark", | |
sublime.HIDDEN | sublime.PERSISTENT) | |
view.hide_popup() | |
def on_hover(self, view, point, hover_zone): | |
# Only handle hovers over the gutter | |
if hover_zone != sublime.HOVER_GUTTER: | |
return | |
# Show a popup; when the link is clicked, trigger the toggle command, | |
# which gets told what file the bookmark should toggle in, and at | |
# what point (Which is the first character of whatever line you | |
# hover next to in the gutter) | |
view.show_popup('<a href="#">Toggle Bookmark</a>', | |
sublime.HIDE_ON_MOUSE_MOVE_AWAY, | |
point, | |
500, 100, | |
lambda href: self.toggle_bookmarks(view, point)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment