Skip to content

Commit

Permalink
Restore folded regions after reloading (#49, thanks to @tinymins)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanliang committed Jan 12, 2015
1 parent bbc75d9 commit d312d35
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ConvertToUTF8.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,12 @@ def run(self, edit, encoding=None, stamp=None, detect_on_fail=False):
sel = view.sel()
rs = [x for x in sel]
vp = view.viewport_position()
view.set_viewport_position(tuple([0, 0]))
view.set_viewport_position((0, 0), False)
view.replace(edit, regions, contents)
sel.clear()
for x in rs:
sel.add(sublime.Region(x.a, x.b))
view.set_viewport_position(vp)
view.set_viewport_position(vp, False)
stamps[file_name] = stamp
sublime.status_message('{0} -> UTF8'.format(encoding))

Expand All @@ -484,6 +484,12 @@ def run(self, edit):
if not encoding or encoding == 'UTF-8':
encoding_cache.pop(file_name)
return
# remember current folded regions
regions = [[x.a, x.b] for x in view.folded_regions()]
if regions:
view.settings().set('folded_regions', regions)
vp = view.viewport_position()
view.settings().set('viewport_position', [vp[0], vp[1]])
fp = None
try:
fp = open(file_name, 'rb')
Expand Down Expand Up @@ -736,6 +742,16 @@ def on_modified(self, view):
def undo_me(self, view):
view.settings().erase('prevent_detect')
view.run_command('undo')
# restore folded regions
regions = view.settings().get('folded_regions')
if regions:
view.settings().erase('folded_regions')
folded = [sublime.Region(int(region[0]), int(region[1])) for region in regions]
view.fold(folded)
vp = view.settings().get('viewport_position')
if vp:
view.settings().erase('viewport_position')
view.set_viewport_position((vp[0], vp[1]), False)
# st3 will reload file immediately
if view.settings().get('revert_to_scratch') or (ST3 and not get_setting(view, 'lazy_reload')):
view.set_scratch(True)
Expand Down
1 change: 1 addition & 0 deletions messages.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"1.2.9": "messages/1.2.9.txt",
"1.2.8": "messages/1.2.8.txt",
"1.2.6": "messages/1.2.6.txt",
"1.2.5": "messages/1.2.5.txt",
Expand Down
7 changes: 7 additions & 0 deletions messages/1.2.9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ConvertToUTF8 1.2.9 Changelog

Enhancements
- Restore folded regions after reloading (#49, thanks to @tinymins)

Fixed
- Malfunction caused by the corrupted cache file

0 comments on commit d312d35

Please sign in to comment.