Skip to content

Instantly share code, notes, and snippets.

@rcherny
Forked from skuroda/add_cursors.py
Created March 1, 2017 17:52
Show Gist options
  • Save rcherny/4afdaa0183761d2f1a07e8c9c558c569 to your computer and use it in GitHub Desktop.
Save rcherny/4afdaa0183761d2f1a07e8c9c558c569 to your computer and use it in GitHub Desktop.
import sublime
import sublime_plugin
class CursorCommand(sublime_plugin.TextCommand):
saved_cursors = set()
def run(self, edit, action="add"):
view = self.view
cursors = view.sel();
if action == "add":
for cursor in cursors:
self.saved_cursors.add(cursor.begin())
elif action == "show":
cursors.clear()
cursors.add_all(self.saved_cursors)
self.saved_cursors.clear()
elif action == "clear":
self.saved_cursors.clear()
elif action == "remove":
for cursor in cursors:
try:
self.saved_cursors.remove(cursor.begin())
except KeyError:
pass
self.highlight_regions()
def highlight_regions(self):
regions = [sublime.Region(x, x) for x in self.saved_cursors]
self.view.add_regions("saved_cursor_region", regions,
"keyword", "", sublime.DRAW_EMPTY)
[
{ "keys": ["f12"], "command": "cursor", "args": {"action": "add"}},
{ "keys": ["f11"], "command": "cursor", "args": {"action": "show"}},
{ "keys": ["f10"], "command": "cursor", "args": {"action": "clear"}},
{ "keys": ["f9"], "command": "cursor", "args": {"action": "remove"}}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment