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.

Revisions

  1. @skuroda skuroda revised this gist Mar 21, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions add_cursors.py
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,11 @@ def run(self, edit, action="add"):
    for cursor in cursors:
    self.saved_cursors_map[view_id].add(cursor.begin())
    elif action == "show" and len(self.saved_cursors_map[view_id]) > 0:
    for cursor in cursors:
    self.saved_cursors_map[view_id].add(cursor.begin())

    cursors.clear()

    for cursor in self.saved_cursors_map[view_id]:
    cursors.add(cursor)
    self.saved_cursors_map[view_id].clear()
  2. @skuroda skuroda revised this gist Mar 21, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion add_cursors.py
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ def run(self, edit, action="add"):
    if action == "add":
    for cursor in cursors:
    self.saved_cursors_map[view_id].add(cursor.begin())
    elif action == "show":
    elif action == "show" and len(self.saved_cursors_map[view_id]) > 0:
    cursors.clear()
    for cursor in self.saved_cursors_map[view_id]:
    cursors.add(cursor)
  3. @skuroda skuroda revised this gist Mar 20, 2013. 1 changed file with 18 additions and 10 deletions.
    28 changes: 18 additions & 10 deletions add_cursors.py
    Original file line number Diff line number Diff line change
    @@ -3,30 +3,38 @@


    class CursorCommand(sublime_plugin.TextCommand):
    saved_cursors = set()
    saved_cursors_map = {}
    def run(self, edit, action="add"):
    view = self.view
    cursors = view.sel()
    view_id = view.id()
    if view_id not in self.saved_cursors_map:
    self.saved_cursors_map[view_id] = set()
    if action == "add":
    for cursor in cursors:
    self.saved_cursors.add(cursor.begin())
    self.saved_cursors_map[view_id].add(cursor.begin())
    elif action == "show":
    cursors.clear()
    for cursor in self.saved_cursors:
    for cursor in self.saved_cursors_map[view_id]:
    cursors.add(cursor)
    self.saved_cursors.clear()
    self.saved_cursors_map[view_id].clear()
    elif action == "clear":
    self.saved_cursors.clear()
    self.saved_cursors_map[view_id].clear()
    elif action == "remove":
    for cursor in cursors:
    try:
    self.saved_cursors.remove(cursor.begin())
    self.saved_cursors_map[view_id].remove(cursor.begin())
    except KeyError:
    pass

    self.highlight_regions()

    def highlight_regions(self):
    regions = [sublime.Region(x, x) for x in self.saved_cursors]
    view_id = self.view.id()
    regions = [sublime.Region(x, x) for x in self.saved_cursors_map[view_id]]
    self.view.add_regions("saved_cursor_region", regions,
    "keyword", "", sublime.DRAW_EMPTY)
    "keyword", "", sublime.DRAW_EMPTY)

    class EventListener(sublime_plugin.EventListener):
    def on_modified(self, view):
    view.run_command("cursor", {"action": "noop"})
  4. @skuroda skuroda revised this gist Mar 20, 2013. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions add_cursors.py
    Original file line number Diff line number Diff line change
    @@ -6,13 +6,14 @@ class CursorCommand(sublime_plugin.TextCommand):
    saved_cursors = set()
    def run(self, edit, action="add"):
    view = self.view
    cursors = view.sel();
    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)
    for cursor in self.saved_cursors:
    cursors.add(cursor)
    self.saved_cursors.clear()
    elif action == "clear":
    self.saved_cursors.clear()
  5. @skuroda skuroda renamed this gist Mar 20, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. @skuroda skuroda created this gist Mar 20, 2013.
    6 changes: 6 additions & 0 deletions Sample Keymap.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    [
    { "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"}}
    ]
    31 changes: 31 additions & 0 deletions add_cursors.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    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)