diff --git a/ConvertToUTF8.py b/ConvertToUTF8.py index c4bbb20..36795cd 100644 --- a/ConvertToUTF8.py +++ b/ConvertToUTF8.py @@ -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)) @@ -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') @@ -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) diff --git a/messages.json b/messages.json index 8c2bc44..43d7022 100644 --- a/messages.json +++ b/messages.json @@ -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", diff --git a/messages/1.2.9.txt b/messages/1.2.9.txt new file mode 100644 index 0000000..d9036c8 --- /dev/null +++ b/messages/1.2.9.txt @@ -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