-
Notifications
You must be signed in to change notification settings - Fork 7
/
LastEdit.py
128 lines (100 loc) · 4.37 KB
/
LastEdit.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import sublime, sublime_plugin
class LastEditCommand(sublime_plugin.TextCommand):
def run(self, edit):
lastView,lastViewLine = getLastEditLine()
# sel = self.view.sel()[0]
# curr_line,_ = self.view.rowcol(sel.begin())
# if curr_line == lastViewLine and self.view.id() == lastView:
# lastView,lastViewLine = getLastEditLine()
if lastView:
lastViewCol = RecordIntputRegion.editLine[lastView][lastViewLine]
jumpLastPoint(jumpLastView(lastView), lastViewLine, lastViewCol)
class SwitchEditViewCommand(sublime_plugin.TextCommand):
def run(self, edit,way="left"):
if way == "left":
lastView = RecordIntputRegion.editView.pop();
RecordIntputRegion.editView.insert(0,lastView);
if lastView == self.view.id():
lastView = RecordIntputRegion.editView.pop();
RecordIntputRegion.editView.insert(0,lastView);
else:
lastView = RecordIntputRegion.editView.pop(0);
RecordIntputRegion.editView.append(lastView);
if lastView == self.view.id():
lastView = RecordIntputRegion.editView.pop(0);
RecordIntputRegion.editView.append(lastView);
jumpLastView(lastView)
def jumpLastView(lastView):
lastViewObj=None
lastWindow = None
for window in sublime.windows():
for view in window.views():
if lastView == view.id():
lastViewObj = view
lastWindow = window
pass
if lastWindow:
lastGroup, _ = lastWindow.get_view_index(lastViewObj)
lastWindow.focus_group(lastGroup)
lastWindow.focus_view(lastViewObj)
return lastViewObj
def jumpLastPoint(lastViewObj,lastViewLine,lastViewCol):
pt = lastViewObj.text_point(lastViewLine,lastViewCol);
lastViewObj.sel().clear();
lastViewObj.sel().add(sublime.Region(pt));
lastViewObj.show(pt);
def getLastEditLine():
lastView = None
lastViewLine = None
lastViewLen = len(RecordIntputRegion.lastView)
if lastViewLen > 0:
viewsCount = lastViewLen - 1
lastView = RecordIntputRegion.lastView[viewsCount]
lastViewPosKey = str(lastView) + ":" + str(viewsCount)
if len(RecordIntputRegion.lastLine[lastViewPosKey]) == 0:
RecordIntputRegion.lastView.pop()
viewsCount = lastViewLen - 1
lastView = RecordIntputRegion.lastView[viewsCount]
lastViewPosKey = str(lastView) + ":" + str(viewsCount)
lastViewLine = RecordIntputRegion.lastLine[lastViewPosKey].pop()
return lastView, lastViewLine
class RecordIntputRegion(sublime_plugin.EventListener):
editLine = {}
lastLine = {}
lastView = []
editView = []
def on_modified(self, view):
sel = view.sel()[0]
curr_view = view.id()
curr_window = view.window().id()
last_line,last_col = view.rowcol(sel.begin())
lastViewPos = len(RecordIntputRegion.lastView)-1
lastSwitchViewPos = len(RecordIntputRegion.editView)-1
if lastViewPos == -1:
RecordIntputRegion.lastView.append(curr_view)
lastViewPos += 1
pass
if not RecordIntputRegion.lastView[lastViewPos] is curr_view:
RecordIntputRegion.lastView.append(curr_view)
lastViewPos += 1
if lastSwitchViewPos == -1:
RecordIntputRegion.editView.append(curr_view)
lastSwitchViewPos += 1
pass
if not RecordIntputRegion.editView[lastSwitchViewPos] is curr_view:
RecordIntputRegion.editView.append(curr_view)
viewPosKey = str(curr_view)+":"+str(lastViewPos)
if not RecordIntputRegion.lastLine.has_key(viewPosKey):
RecordIntputRegion.lastLine[viewPosKey]=[]
pass
lastLinePos = len(RecordIntputRegion.lastLine[viewPosKey]) -1;
if lastLinePos == -1:
RecordIntputRegion.lastLine[viewPosKey].append(last_line);
lastLinePos +=1;
if not RecordIntputRegion.lastLine[viewPosKey][lastLinePos] is last_line:
RecordIntputRegion.lastLine[viewPosKey].append(last_line)
pass
if not RecordIntputRegion.editLine.has_key(curr_view):
RecordIntputRegion.editLine[curr_view]={}
pass
RecordIntputRegion.editLine[curr_view][last_line] = last_col