-
Notifications
You must be signed in to change notification settings - Fork 9
/
q_select_text.py
69 lines (57 loc) · 1.96 KB
/
q_select_text.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
from . import q_chain
class QSelectTextCommand(q_chain.QChainCommand):
def do(self, edit, input=None):
# get s
s = QSelectTextCommand.selectText(self.view)
# only proceed if s is not empty
if(s == "" or s == "\n"):
return
else:
return s
@staticmethod
def selectText(view):
s = ""
for region in view.sel():
if region.empty():
s += view.substr(view.line(region))
#if advanceCursor:
# advanceCursor(region)
else:
s += view.substr(region)
return s
#not used
def advanceCursor(self, region):
(row, col) = self.view.rowcol(region.begin())
# Make sure not to go past end of next line
nextline = self.view.line(self.view.text_point(row + 1, 0))
if nextline.size() < col:
loc = self.view.text_point(row + 1, nextline.size())
else:
loc = self.view.text_point(row + 1, col)
# Remove the old region and add the new one
self.view.sel().subtract(region)
self.view.sel().add(sublime.Region(loc, loc))
class QSelectWordCommand(q_chain.QChainCommand):
def do(self, edit, input=None):
s = QSelectWordCommand.selectWord(self.view)
# only proceed if s is not empty
if(s == "" or s == "\n"):
return
else:
return s
@staticmethod
def selectWord(view):
# grab the word or the selection from the view
s = ""
region = view.sel()[0]
location = False
if region.empty():
# if we have no selection grab the current word
location = view.word(region)
else:
# grab the selection
location = region
if location and not location.empty():
s = view.substr(location)
#scope = view.scope_name(location.begin()).rpartition('.')[2].strip()
return s