-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_next_in_cursors.py
78 lines (69 loc) · 2.8 KB
/
find_next_in_cursors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import sublime, sublime_plugin
class SelectToNextCommand(sublime_plugin.TextCommand):
saved_pattern = ""
def run(self, edit):
# cb = sublime.get_clipboard()
def done(pattern):
self.saved_pattern = pattern
# we take end of selection for start point in search
existing_selections = [x for x in self.view.sel()]
# resulting_selection = []
e = self.view.begin_edit()
self.view.sel().clear()
for selection in existing_selections:
found_selection = self.view.find(pattern, selection.b, sublime.LITERAL | sublime.IGNORECASE)
if found_selection != None:
# resulting_selection.append(found_selection)
new_selection = sublime.Region(selection.a, found_selection.b)
self.view.sel().add( new_selection )
# print "added selection:", new_selection
self.view.end_edit(e)
# print "total selections:", self.view.sel()
sublime.active_window().show_input_panel("select to next pattern: ", self.saved_pattern, done, None, None)
class MoveToNextCommand(sublime_plugin.TextCommand):
"""
a = [(467, 467), (478, 478)]
[view.sel().add( sublime.Region(view.text_point(x[1], x[0])) ) for x in a]
[sublime.Region(view.text_point(x[1], x[0])) for x in a]
[view.text_point(x[1], x[0]) for x in a]
[sublime.Region(x[0], x[1]) for x in a]
[view.sel().add( sublime.Region(x[0], x[1]) ) for x in a]
[x.b for x in view.sel()]
"""
saved_pattern = ""
def run(self, edit):
# cb = sublime.get_clipboard()
def done(pattern):
self.saved_pattern = pattern
# we take end of selection for start point in search
cursor_points = [x.b for x in self.view.sel()]
# resulting_selection = []
e = self.view.begin_edit()
self.view.sel().clear()
for point in cursor_points:
region = self.view.find(pattern, point, sublime.LITERAL | sublime.IGNORECASE)
if region != None:
# resulting_selection.append(region)
self.view.sel().add(region)
self.view.end_edit(e)
sublime.active_window().show_input_panel("move cursors to next pattern: ", self.saved_pattern, done, None, None)
class KeepEveryNthCursorCommand(sublime_plugin.TextCommand):
"""
From all existing cursor keep every nth starting from first.
"""
saved_number = 1
def run(self, edit):
# cb = sublime.get_clipboard()
def done(number):
self.saved_number = int(number)
# we take end of selection for start point in search
cursors_to_keep = []
for index, selection in enumerate(self.view.sel()):
if index % self.saved_number == 0:
cursors_to_keep.append(selection)
e = self.view.begin_edit()
self.view.sel().clear()
for selection in cursors_to_keep:
self.view.sel().add(selection)
self.view.end_edit(e)
sublime.active_window().show_input_panel("Nth integer: ", str(self.saved_number), done, None, None)