Skip to content

Commit ce86f08

Browse files
committed
added rainbow option that use different colors for multiple markers
1 parent 3a2ea37 commit ce86f08

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

StickySearch.py

+40-10
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,62 @@
22

33
#view.run_command("stickysearch")
44
class StickysearchCommand(sublime_plugin.TextCommand):
5+
_scopes = [
6+
"region.yellowish",
7+
"region.bluish",
8+
"region.redish",
9+
"region.orangish",
10+
"region.greenish",
11+
"region.cyanish",
12+
"region.purplish",
13+
"region.pinkish",
14+
]
15+
_keys = []
16+
_keybase = "StickySearch"
17+
518
def run(self, edit, op):
619
# keep sticky per window (each window has its own set)
7-
view = self.view
8-
key = "StickySearch"
9-
1020
if 'add' in op:
11-
regions = self.find_all_under_cursor(self.view) + view.get_regions(key)
12-
self.mark(key, view, regions)
21+
self.op_add()
1322
if 'clear' in op:
14-
view.erase_regions(key)
23+
self.op_clear()
1524
if 'set' in op:
16-
regions = self.find_all_under_cursor(self.view)
17-
self.mark(key, view, regions)
25+
self.op_clear()
26+
self.op_add()
27+
28+
def op_add(self):
29+
regions = self.find_all_under_cursor(self.view)
30+
key = self._keybase + str(len(self._keys))
31+
self.mark(key, self.view, regions)
32+
self._keys.append(key)
33+
34+
def op_clear(self):
35+
for key in self._keys:
36+
self.view.erase_regions(key)
37+
self._keys = []
1838

1939
def mark(self, key, view, regions):
2040
settings = sublime.load_settings("StickySearch.sublime-settings")
21-
icon_name = settings.get("icon", "dot")
2241
flags = sublime.PERSISTENT
2342
if not settings.get("fill", False):
2443
flags |= sublime.DRAW_NO_FILL
2544
if not settings.get("outline", True):
2645
flags |= sublime.DRAW_NO_OUTLINE
46+
2747
# optional icon name, if given, will draw the named icons in the gutter next to each region.
2848
# The icon will be tinted using the color associated with the scope.
2949
# Valid icon names are dot, circle, bookmark and cross
30-
view.add_regions(key, regions, "marker", icon_name, flags)
50+
icon_name = settings.get("icon", "dot")
51+
52+
# optional string used to source a color to draw the regions in. The scope is matched
53+
# against the color scheme.
54+
next_marker_index = len(self._keys)
55+
num_of_available_scopes = len(self._scopes)
56+
if settings.get("rainbow", True):
57+
scope = self._scopes[next_marker_index % num_of_available_scopes]
58+
else:
59+
scope = "region.yellowish"
60+
view.add_regions(key, regions, scope, icon_name, flags)
3161

3262
def find_all_under_cursor(self, view):
3363
# view.window().run_command('find_all_under')

StickySearch.sublime-settings

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
"icon": "dot",
77
// Style of search highlighting
88
"fill": false,
9-
"outline": true
9+
"outline": true,
10+
// Use different colors for additional selections
11+
"rainbow": true
1012
}

0 commit comments

Comments
 (0)