Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 394 lines (367 sloc) 16.795 kb
cae2d21 @agibsonsw First full commit
authored
1 import sublime, sublime_plugin
2 from os import path
fd37eb1 @agibsonsw Output edit info option
authored
3 import datetime
cae2d21 @agibsonsw First full commit
authored
4
5 PACKAGE_SETTINGS = "AndyEdits.sublime-settings"
6 if sublime.platform() == "linux":
7 # Try and load Linux Python2.6 lib. Default path is for Ubuntu.
8 linux_lib = sublime.load_settings(PACKAGE_SETTINGS).get("linux_python2.6_lib",
9 "/usr/lib/python2.6/lib-dynload")
10 if not linux_lib in sys.path and path.exists(linux_lib):
11 sys.path.append(linux_lib)
12
5e0ea6e @agibsonsw Changed settings
authored
13 # ICON: a small icon to appear in the gutter - defaults to True (use pencil)
14 if sublime.load_settings(PACKAGE_SETTINGS).get("use_icon", True):
15 if sublime.load_settings(PACKAGE_SETTINGS).get("ST_icon", False):
16 ICON = sublime.load_settings(PACKAGE_SETTINGS).get("ST_icon")
17 else:
18 ICON = path.pardir + '/AndyEdits/icon'
19 else:
20 ICON = ""
21
cae2d21 @agibsonsw First full commit
authored
22 ICONSCOPE = sublime.load_settings(PACKAGE_SETTINGS).get("icon_scope", "comment")
23 # affects the colour of the gutter icon and outlining
6259b7f @agibsonsw Collapse tabs and spaces only
authored
24 ICONCURRENT = sublime.load_settings(PACKAGE_SETTINGS).get("icon_current", "comment")
5e0ea6e @agibsonsw Changed settings
authored
25 # affects the colour of the gutter icon for the current edit-region
8771617 @agibsonsw Outlining saved regions
authored
26 SAVEDSCOPE = sublime.load_settings(PACKAGE_SETTINGS).get("saved_scope", "keyword")
cae2d21 @agibsonsw First full commit
authored
27
8771617 @agibsonsw Outlining saved regions
authored
28 SAVED_EDITS = sublime.load_settings(PACKAGE_SETTINGS).get("saved_edits", False)
fd37eb1 @agibsonsw Output edit info option
authored
29 OUTPUT_EDITS = sublime.load_settings(PACKAGE_SETTINGS).get("output_edits", False)
8771617 @agibsonsw Outlining saved regions
authored
30
1c645f2 @agibsonsw Edits per view
authored
31 JUSTDELETED = {}
22aef01 @agibsonsw Correction to added region
authored
32 # Uses view.id() as key and a single boolean True/False value.
51d2846 @agibsonsw Different pencil colours
authored
33 # (Prevents a deleted region from being immediately re-created.)
1c645f2 @agibsonsw Edits per view
authored
34
4226f4e @agibsonsw List all edits
authored
35 def showRegion(view, reg):
36 view.sel().clear()
37 view.sel().add(reg)
1302f80 @agibsonsw Almost perfect!
authored
38 view.show(reg)
4226f4e @agibsonsw List all edits
authored
39
68cf854 @agibsonsw Minor adjustments
authored
40 def isView(view_id):
4226f4e @agibsonsw List all edits
authored
41 if not view_id: return False
42 window = sublime.active_window()
43 view = window.active_view() if window != None else None
44 return (view is not None and view.id() == view_id)
45
cae2d21 @agibsonsw First full commit
authored
46 def adjustEdits(view):
8120c79 @agibsonsw Refinement
authored
47 # Add recently edited line to all previous edits,
48 # also joins consecutive edit lines together.
49 # Returns: the edited regions or False if there are none.
cae2d21 @agibsonsw First full commit
authored
50 edited = view.get_regions("edited_rgns") or []
51 edited_last = view.get_regions("edited_rgn") or []
52 if not edited and not edited_last:
53 return False
54 new_edits = []
4226f4e @agibsonsw List all edits
authored
55 if edited_last:
56 edited.extend(edited_last)
a0b9b5c @agibsonsw Can create edit regions
authored
57 eov = view.size()
fa02151 @agibsonsw Improved previous edit line cover
authored
58 view.erase_regions("edited_rgns")
f3a07d3 @agibsonsw Consecutive lines
authored
59 for i, r in enumerate(sorted(edited)):
60 if i > 0 and r.begin() <= prev_end + 1:
358f0ab @agibsonsw Do not drop onto next line
authored
61 # collapse adjoining regions
80c1eb4 @agibsonsw Insert rather than append
authored
62 new_edits.pop()
fa02151 @agibsonsw Improved previous edit line cover
authored
63 r = sublime.Region(prev_begin, max(r.end(), prev_end))
a0b9b5c @agibsonsw Can create edit regions
authored
64 elif r.begin() < eov:
6259b7f @agibsonsw Collapse tabs and spaces only
authored
65 curr_line, _ = view.rowcol(r.begin())
66 if i > 0 and curr_line == prev_line + 1:
556d97a @agibsonsw Do not adjust during Find
authored
67 # Check if there are ony spaces and/or tabs between 2 regions
68 # (on adjacent lines); if so, treat as a single edit-region.
6259b7f @agibsonsw Collapse tabs and spaces only
authored
69 inter_region = sublime.Region(prev_end + 1, r.begin() - 1) if \
70 (prev_end + 1 < r.begin() - 1) else None
71 if inter_region:
72 inter_content = view.substr(inter_region)
fa02151 @agibsonsw Improved previous edit line cover
authored
73 inter_content = inter_content.strip()
6259b7f @agibsonsw Collapse tabs and spaces only
authored
74 if inter_content == '' or inter_content is None:
80c1eb4 @agibsonsw Insert rather than append
authored
75 new_edits.pop()
fa02151 @agibsonsw Improved previous edit line cover
authored
76 r = sublime.Region(prev_begin, max(r.end(), prev_end))
80c1eb4 @agibsonsw Insert rather than append
authored
77 new_edits.append(r)
cae2d21 @agibsonsw First full commit
authored
78 prev_begin, prev_end = (r.begin(), r.end())
6259b7f @agibsonsw Collapse tabs and spaces only
authored
79 prev_line, _ = view.rowcol(prev_end)
cae2d21 @agibsonsw First full commit
authored
80 view.add_regions("edited_rgns", new_edits, ICONSCOPE, ICON, \
81 sublime.HIDDEN | sublime.PERSISTENT)
82 return view.get_regions("edited_rgns") or []
83
358f0ab @agibsonsw Do not drop onto next line
authored
84 def getEditList(view, edited):
85 the_edits = []
ba17a49 @agibsonsw Asterisk for current edit (in panels)
authored
86 curr_edit = view.get_regions("edited_rgn") or []
87 curr_edit = curr_edit[0] if curr_edit else None
358f0ab @agibsonsw Do not drop onto next line
authored
88 for i, r in enumerate(edited):
89 curr_line, _ = view.rowcol(r.begin())
28bc8fd @agibsonsw Delete message in quick panel.
authored
90 curr_text = view.substr(r).strip()[:50]
358f0ab @agibsonsw Do not drop onto next line
authored
91 if not len(curr_text):
28bc8fd @agibsonsw Delete message in quick panel.
authored
92 curr_text = view.substr(view.line(r)).strip()[:50] + " (line)"
ba17a49 @agibsonsw Asterisk for current edit (in panels)
authored
93 if curr_edit and r.intersects(curr_edit):
94 display_line = "*%03d %s" % (curr_line + 1, curr_text)
95 else:
96 display_line = " %03d %s" % (curr_line + 1, curr_text)
97 the_edits.append(display_line)
358f0ab @agibsonsw Do not drop onto next line
authored
98 return the_edits
99
4226f4e @agibsonsw List all edits
authored
100 def getFullEditList(view, edited):
101 the_edits = []
102 locations = []
ba17a49 @agibsonsw Asterisk for current edit (in panels)
authored
103 curr_edit = view.get_regions("edited_rgn") or []
104 curr_edit = curr_edit[0] if curr_edit else None
4226f4e @agibsonsw List all edits
authored
105 for i, r in enumerate(edited):
106 curr_line, _ = view.rowcol(r.begin())
28bc8fd @agibsonsw Delete message in quick panel.
authored
107 curr_text = view.substr(r).strip()[:50]
4226f4e @agibsonsw List all edits
authored
108 if not len(curr_text):
28bc8fd @agibsonsw Delete message in quick panel.
authored
109 curr_text = view.substr(view.line(r)).strip()[:50] + " (line)"
ba17a49 @agibsonsw Asterisk for current edit (in panels)
authored
110 if curr_edit and r.intersects(curr_edit):
111 display_line = " * %03d %s" % (curr_line + 1, curr_text)
112 else:
113 display_line = " %03d %s" % (curr_line + 1, curr_text)
114 the_edits.append(display_line)
4226f4e @agibsonsw List all edits
authored
115 locations.append((view, r))
116 return the_edits, locations
117
118 class ListAllEdits(sublime_plugin.WindowCommand):
119 def run(self):
120 full_list = []
121 self.locations = []
122 for vw in self.window.views():
51d2846 @agibsonsw Different pencil colours
authored
123 edited = adjustEdits(vw)
4226f4e @agibsonsw List all edits
authored
124 if edited:
125 the_edits, locs = getFullEditList(vw, edited)
126 if the_edits:
127 the_edits.insert(0, "%s" % (vw.file_name() or "No filename"))
1302f80 @agibsonsw Almost perfect!
authored
128 locs.insert(0, (vw, vw.sel()[0]))
4226f4e @agibsonsw List all edits
authored
129 full_list += the_edits
130 self.locations += locs
131 if full_list:
132 self.window.show_quick_panel(full_list, self.on_chosen)
133 else:
134 sublime.status_message('No edits to list.')
135
136 def on_chosen(self, index):
137 if index == -1: return
138 vw, reg = self.locations[index]
139 sublime.active_window().focus_view(vw)
140 showRegion(vw, reg)
728a85c @agibsonsw Complete!
authored
141 del self.locations[:]
4226f4e @agibsonsw List all edits
authored
142
cae2d21 @agibsonsw First full commit
authored
143 class ToggleEditsCommand(sublime_plugin.TextCommand):
8120c79 @agibsonsw Refinement
authored
144 # Toggles outlining of edited lines.
cae2d21 @agibsonsw First full commit
authored
145 def run(self, edit):
68cf854 @agibsonsw Minor adjustments
authored
146 if not isView(self.view.id()):
cae2d21 @agibsonsw First full commit
authored
147 sublime.status_message('Click into the view/tab first.')
148 return
149 edited = adjustEdits(self.view)
150 if not edited:
151 sublime.status_message('No edits to show or hide.')
152 return
153 toggled = self.view.get_regions("toggled_edits") or []
154 if toggled:
155 self.view.erase_regions("toggled_edits")
156 else:
157 self.view.add_regions("toggled_edits", edited, ICONSCOPE, \
158 ICON, sublime.DRAW_OUTLINED)
5e0ea6e @agibsonsw Changed settings
authored
159 sublime.status_message("There are %d edit region(s)." % (len(edited)))
cae2d21 @agibsonsw First full commit
authored
160
161 class PrevEditLineCommand(sublime_plugin.TextCommand):
162 def run(self, edit):
68cf854 @agibsonsw Minor adjustments
authored
163 if not isView(self.view.id()):
cae2d21 @agibsonsw First full commit
authored
164 sublime.status_message('Click into the view/tab first.')
165 return
166 currA = self.view.sel()[0].begin()
167 edited = adjustEdits(self.view)
168 if not edited:
169 sublime.status_message('No edits to go to.')
170 return
171 for reg in [r for r in reversed(edited) if r.begin() < currA]:
172 showRegion(self.view, reg)
173 break
174 else:
175 sublime.status_message('No edits further up.')
176
177 class NextEditLineCommand(sublime_plugin.TextCommand):
178 def run(self, edit):
68cf854 @agibsonsw Minor adjustments
authored
179 if not isView(self.view.id()):
cae2d21 @agibsonsw First full commit
authored
180 sublime.status_message('Click into the view/tab first.')
181 return
182 currA = self.view.sel()[0].begin()
183 edited = adjustEdits(self.view)
184 if not edited:
185 sublime.status_message('No edits to go to.')
186 return
187 for reg in [r for r in edited if r.begin() > currA]:
188 showRegion(self.view, reg)
189 break
190 else:
191 sublime.status_message('No edits further down.')
192
a0b9b5c @agibsonsw Can create edit regions
authored
193 class CreateEditCommand(sublime_plugin.TextCommand):
ff0c702 @agibsonsw Just another status message.
authored
194 # Create an edit region for the current selection.
a0b9b5c @agibsonsw Can create edit regions
authored
195 def run(self, edit):
68cf854 @agibsonsw Minor adjustments
authored
196 if not isView(self.view.id()):
a0b9b5c @agibsonsw Can create edit regions
authored
197 sublime.status_message('Click into the view/tab first.')
198 return
91d4ecf @agibsonsw Create edit was bool
authored
199 edited = adjustEdits(self.view) or []
a0b9b5c @agibsonsw Can create edit regions
authored
200 curr_region = self.view.sel()[0]
201 if curr_region.empty():
202 sublime.status_message('You must select some text.')
203 return
204 edited.append(curr_region)
556d97a @agibsonsw Do not adjust during Find
authored
205 self.view.erase_regions("edited_rgns")
a0b9b5c @agibsonsw Can create edit regions
authored
206 self.view.add_regions("edited_rgns", edited, ICONSCOPE, ICON, \
207 sublime.HIDDEN | sublime.PERSISTENT)
208 sublime.status_message('New edit region created.')
209
cae2d21 @agibsonsw First full commit
authored
210 class QuickEditsCommand(sublime_plugin.TextCommand):
8120c79 @agibsonsw Refinement
authored
211 # Shows a quick panel to jump to edit lines.
cae2d21 @agibsonsw First full commit
authored
212 def run(self, edit):
358f0ab @agibsonsw Do not drop onto next line
authored
213 self.vid = self.view.id()
68cf854 @agibsonsw Minor adjustments
authored
214 if not isView(self.vid):
cae2d21 @agibsonsw First full commit
authored
215 sublime.status_message('Click into the view/tab first.')
216 return
217 edited = adjustEdits(self.view)
218 if not edited:
219 sublime.status_message('No edits to list.')
220 return
358f0ab @agibsonsw Do not drop onto next line
authored
221 the_edits = getEditList(self.view, edited)
222 if the_edits:
223 sublime.active_window().show_quick_panel(the_edits, self.on_chosen)
cae2d21 @agibsonsw First full commit
authored
224
225 def on_chosen(self, index):
226 if index == -1: return
68cf854 @agibsonsw Minor adjustments
authored
227 if not isView(self.vid):
cae2d21 @agibsonsw First full commit
authored
228 sublime.status_message('You are in a different view.')
229 return
230 edited = self.view.get_regions("edited_rgns") or []
231 for reg in [r for i, r in enumerate(edited) if i == index]:
232 showRegion(self.view, reg)
233 break
234
9e6d1a3 @agibsonsw Corrections
authored
235 class DeleteEditCommand(sublime_plugin.TextCommand):
236 # Shows a quick panel to remove edit history for a region.
237 def run(self, edit):
358f0ab @agibsonsw Do not drop onto next line
authored
238 self.vid = self.view.id()
68cf854 @agibsonsw Minor adjustments
authored
239 if not isView(self.vid):
9e6d1a3 @agibsonsw Corrections
authored
240 sublime.status_message('Click into the view/tab first.')
241 return
242 edited = adjustEdits(self.view)
243 if not edited:
244 sublime.status_message('No edit history to delete.')
245 return
358f0ab @agibsonsw Do not drop onto next line
authored
246 the_edits = getEditList(self.view, edited)
247 if the_edits:
28bc8fd @agibsonsw Delete message in quick panel.
authored
248 the_edits.insert(0, " -- DELETE EDIT REGION (except most recent) -- ")
358f0ab @agibsonsw Do not drop onto next line
authored
249 sublime.active_window().show_quick_panel(the_edits, self.on_chosen)
9e6d1a3 @agibsonsw Corrections
authored
250
251 def removeTempHighlight(self, old_line):
252 self.view.erase_regions("temp_del")
253 sublime.status_message("Edit history removed from line %d." % old_line)
254
255 def on_chosen(self, index):
28bc8fd @agibsonsw Delete message in quick panel.
authored
256 if index <= 0: return
68cf854 @agibsonsw Minor adjustments
authored
257 if not isView(self.vid):
9e6d1a3 @agibsonsw Corrections
authored
258 sublime.status_message('You are in a different view.')
259 return
260 edited = self.view.get_regions("edited_rgns") or []
28bc8fd @agibsonsw Delete message in quick panel.
authored
261 reg = edited[index - 1]
88df24d @agibsonsw Correction to delete
authored
262 current_editr = self.view.get_regions("edited_rgn") or []
263 if current_editr and reg.intersects(current_editr[0]):
1b44e60 @agibsonsw Message about deletions
authored
264 sublime.status_message('Cannot delete most recent edit.')
265 return
28bc8fd @agibsonsw Delete message in quick panel.
authored
266 del edited[index - 1]
556d97a @agibsonsw Do not adjust during Find
authored
267 self.view.erase_regions("edited_rgns")
9e6d1a3 @agibsonsw Corrections
authored
268 self.view.add_regions("edited_rgns", edited, ICONSCOPE, ICON, \
269 sublime.HIDDEN | sublime.PERSISTENT)
51d2846 @agibsonsw Different pencil colours
authored
270 toggled = self.view.get_regions("toggled_edits") or []
271 if toggled:
556d97a @agibsonsw Do not adjust during Find
authored
272 self.view.erase_regions("toggled_edits")
51d2846 @agibsonsw Different pencil colours
authored
273 self.view.add_regions("toggled_edits", edited, ICONSCOPE, \
274 ICON, sublime.DRAW_OUTLINED)
9e6d1a3 @agibsonsw Corrections
authored
275 old_line, _ = self.view.rowcol(reg.begin())
358f0ab @agibsonsw Do not drop onto next line
authored
276 self.view.add_regions("temp_del", [reg], "invalid", sublime.DRAW_OUTLINED)
9e6d1a3 @agibsonsw Corrections
authored
277 sublime.set_timeout(lambda: self.removeTempHighlight(old_line + 1), 500)
c4c1e2d @agibsonsw Correcting Undo
authored
278 JUSTDELETED[self.vid] = True
9e6d1a3 @agibsonsw Corrections
authored
279
cae2d21 @agibsonsw First full commit
authored
280 class CaptureEditing(sublime_plugin.EventListener):
1c645f2 @agibsonsw Edits per view
authored
281 edit_info = {}
cae2d21 @agibsonsw First full commit
authored
282 def on_modified(self, view):
8120c79 @agibsonsw Refinement
authored
283 # Create hidden regions that mirror the edited regions.
284 # Maintains a single edit region for the current line.
51d2846 @agibsonsw Different pencil colours
authored
285 vid = view.id()
286 if not isView(vid):
cae2d21 @agibsonsw First full commit
authored
287 return
f367140 @agibsonsw Replace has_key
authored
288 if not vid in CaptureEditing.edit_info:
1c645f2 @agibsonsw Edits per view
authored
289 CaptureEditing.edit_info[vid] = {}
290 cview = CaptureEditing.edit_info[vid]
cae2d21 @agibsonsw First full commit
authored
291 sel = view.sel()[0]
292 currA, currB = (sel.begin(), sel.end())
1c645f2 @agibsonsw Edits per view
authored
293 cview['curr_line'], _ = view.rowcol(currA)
f367140 @agibsonsw Replace has_key
authored
294 if not ('prev_line' in cview) or cview['prev_line'] is None:
a89a0d1 @agibsonsw Move screenshots
authored
295 # on first run, or just deleted an edit region
1c645f2 @agibsonsw Edits per view
authored
296 cview['prev_line'] = cview['curr_line']
cae2d21 @agibsonsw First full commit
authored
297 if currA > 0 and sel.empty():
358f0ab @agibsonsw Do not drop onto next line
authored
298 # include the first character?
9e6d1a3 @agibsonsw Corrections
authored
299 same_line, _ = view.rowcol(currA - 1)
1c645f2 @agibsonsw Edits per view
authored
300 if cview['curr_line'] == same_line:
9e6d1a3 @agibsonsw Corrections
authored
301 currA -= 1
556d97a @agibsonsw Do not adjust during Find
authored
302 cview['to_eol'] = (currB == view.line(currB).end())
1c645f2 @agibsonsw Edits per view
authored
303 cview['lastx'], cview['lasty'] = (currA, currB)
304 elif cview['curr_line'] == cview['prev_line']:
8120c79 @agibsonsw Refinement
authored
305 # still on the same line
1c645f2 @agibsonsw Edits per view
authored
306 cview['lastx'] = min(currA, cview['lastx'])
56beb63 @agibsonsw Handles auto-insertions better
authored
307 if cview['to_eol']:
556d97a @agibsonsw Do not adjust during Find
authored
308 cview['lasty'] = view.line(currB).end()
56beb63 @agibsonsw Handles auto-insertions better
authored
309 else:
310 # don't go beyond end of current line..
311 cview['lasty'] = max(currB, min(cview['lasty'] + 1, \
312 view.line(sel).end()))
cae2d21 @agibsonsw First full commit
authored
313 else:
8120c79 @agibsonsw Refinement
authored
314 # moving to a different line
13a1fb4 @agibsonsw Attempt to correct prev line removed pro tem
authored
315 # if cview['to_eol']:
316 # # adjust previous edit region to end-of-line
317 # prev_editl = view.get_regions("edited_rgn") or []
318 # if prev_editl:
319 # prev_editl = prev_editl[0]
320 # prev_editl = sublime.Region(prev_editl.begin(), \
321 # view.line(prev_editl.begin()).end())
322 # view.erase_regions("edited_rgn")
323 # view.add_regions("edited_rgn", [prev_editl], ICONCURRENT, \
324 # ICON, sublime.HIDDEN | sublime.PERSISTENT)
1c645f2 @agibsonsw Edits per view
authored
325 cview['prev_line'] = cview['curr_line']
cae2d21 @agibsonsw First full commit
authored
326 if currA > 0 and sel.empty():
358f0ab @agibsonsw Do not drop onto next line
authored
327 # include the first character?
9e6d1a3 @agibsonsw Corrections
authored
328 same_line, _ = view.rowcol(currA - 1)
1c645f2 @agibsonsw Edits per view
authored
329 if cview['curr_line'] == same_line:
9e6d1a3 @agibsonsw Corrections
authored
330 currA -= 1
556d97a @agibsonsw Do not adjust during Find
authored
331 cview['to_eol'] = (currB == view.line(currB).end())
1c645f2 @agibsonsw Edits per view
authored
332 cview['lastx'], cview['lasty'] = (currA, currB)
9e6d1a3 @agibsonsw Corrections
authored
333 _ = adjustEdits(view)
22aef01 @agibsonsw Correction to added region
authored
334 if cview['lastx'] < cview['lasty']:
335 curr_edit = sublime.Region(cview['lastx'], cview['lasty'])
556d97a @agibsonsw Do not adjust during Find
authored
336 view.erase_regions("edited_rgn")
6259b7f @agibsonsw Collapse tabs and spaces only
authored
337 view.add_regions("edited_rgn", [curr_edit], ICONCURRENT, \
22aef01 @agibsonsw Correction to added region
authored
338 ICON, sublime.HIDDEN | sublime.PERSISTENT)
572dede @agibsonsw Trying to correct Undo
authored
339
340 def on_selection_modified(self, view):
51d2846 @agibsonsw Different pencil colours
authored
341 vid = view.id()
342 if not isView(vid):
07b68dc @agibsonsw Prevent on_selec running in dialogs
authored
343 return
f367140 @agibsonsw Replace has_key
authored
344 if not vid in CaptureEditing.edit_info:
1c645f2 @agibsonsw Edits per view
authored
345 CaptureEditing.edit_info[vid] = {}
346 cview = CaptureEditing.edit_info[vid]
f367140 @agibsonsw Replace has_key
authored
347 if vid in JUSTDELETED and JUSTDELETED[vid] == True:
556d97a @agibsonsw Do not adjust during Find
authored
348 JUSTDELETED[vid], cview['prev_line'] = (False, None)
c4c1e2d @agibsonsw Correcting Undo
authored
349 return
f367140 @agibsonsw Replace has_key
authored
350 if ('prev_line' in cview) and cview['prev_line'] is not None:
572dede @agibsonsw Trying to correct Undo
authored
351 curr_line, _ = view.rowcol(view.sel()[0].begin())
22aef01 @agibsonsw Correction to added region
authored
352 if (cview['prev_line'] != curr_line) and (cview['lastx'] < cview['lasty']):
572dede @agibsonsw Trying to correct Undo
authored
353 edited = view.get_regions('edited_rgns') or []
5e0ea6e @agibsonsw Changed settings
authored
354 for i, r in enumerate(edited):
5b1f7d4 @agibsonsw Minor improvement
authored
355 if r.begin() >= cview['lastx'] and r.end() <= cview['lasty']:
5e0ea6e @agibsonsw Changed settings
authored
356 break
357 else:
5b1f7d4 @agibsonsw Minor improvement
authored
358 edited.append(sublime.Region(cview['lastx'], cview['lasty']))
556d97a @agibsonsw Do not adjust during Find
authored
359 view.erase_regions("edited_rgns")
51d2846 @agibsonsw Different pencil colours
authored
360 view.add_regions("edited_rgns", edited, ICONSCOPE, \
361 ICON, sublime.HIDDEN | sublime.PERSISTENT)
8e29fbe @agibsonsw On close, delete dict entry.
authored
362 cview['prev_line'] = None
363
364 def on_close(self, view):
365 vid = view.id()
f367140 @agibsonsw Replace has_key
authored
366 if vid in CaptureEditing.edit_info:
fd37eb1 @agibsonsw Output edit info option
authored
367 del CaptureEditing.edit_info[vid]
368
369 def on_post_save(self, view):
8771617 @agibsonsw Outlining saved regions
authored
370 if not SAVED_EDITS: return
fd37eb1 @agibsonsw Output edit info option
authored
371 vid = view.id()
372 re_activate = isView(vid)
8771617 @agibsonsw Outlining saved regions
authored
373 if not re_activate: return
fd37eb1 @agibsonsw Output edit info option
authored
374 _ = adjustEdits(view)
8771617 @agibsonsw Outlining saved regions
authored
375 saved_edits = view.get_regions('edited_rgns')
fd37eb1 @agibsonsw Output edit info option
authored
376 if not saved_edits: return
8771617 @agibsonsw Outlining saved regions
authored
377 view.add_regions("saved_rgns", saved_edits, SAVEDSCOPE, \
20440ee @agibsonsw Persistent saved outline
authored
378 ICON, sublime.PERSISTENT | sublime.DRAW_OUTLINED)
8771617 @agibsonsw Outlining saved regions
authored
379
380 if not OUTPUT_EDITS: return
fd37eb1 @agibsonsw Output edit info option
authored
381 newview = sublime.active_window().new_file()
382 edit = newview.begin_edit()
383 newview.insert(edit, 0, view.file_name() + "\n")
384 newview.insert(edit, newview.size(),
385 datetime.datetime.now().strftime("%c") + '\n')
386
387 for i, r in enumerate(sorted(saved_edits)):
388 editline, _ = view.rowcol(r.begin())
389 newview.insert(edit, newview.size(), "\n-----\nLine: " + \
390 str(editline) + '\n')
391 newview.insert(edit, newview.size(), view.substr(r))
392 newview.end_edit(edit)
393 if re_activate:
394 sublime.active_window().focus_view(view)
Something went wrong with that request. Please try again.