|
2 | 2 |
|
3 | 3 | #view.run_command("stickysearch")
|
4 | 4 | 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 | + |
5 | 18 | def run(self, edit, op):
|
6 | 19 | # keep sticky per window (each window has its own set)
|
7 |
| - view = self.view |
8 |
| - key = "StickySearch" |
9 |
| - |
10 | 20 | 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() |
13 | 22 | if 'clear' in op:
|
14 |
| - view.erase_regions(key) |
| 23 | + self.op_clear() |
15 | 24 | 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 = [] |
18 | 38 |
|
19 | 39 | def mark(self, key, view, regions):
|
20 | 40 | settings = sublime.load_settings("StickySearch.sublime-settings")
|
21 |
| - icon_name = settings.get("icon", "dot") |
22 | 41 | flags = sublime.PERSISTENT
|
23 | 42 | if not settings.get("fill", False):
|
24 | 43 | flags |= sublime.DRAW_NO_FILL
|
25 | 44 | if not settings.get("outline", True):
|
26 | 45 | flags |= sublime.DRAW_NO_OUTLINE
|
| 46 | + |
27 | 47 | # optional icon name, if given, will draw the named icons in the gutter next to each region.
|
28 | 48 | # The icon will be tinted using the color associated with the scope.
|
29 | 49 | # 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) |
31 | 61 |
|
32 | 62 | def find_all_under_cursor(self, view):
|
33 | 63 | # view.window().run_command('find_all_under')
|
|
0 commit comments