Skip to content

Commit

Permalink
Added "reset_diff_markers" setting for resetting the diff markers in …
Browse files Browse the repository at this point in the history
…the gutter (defaults to true)
  • Loading branch information
seanliang committed Mar 14, 2019
1 parent cddb6a9 commit 1c6c2ac
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions ConvertToUTF8.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
REVERTING_FILES = []

CONFIRM_IS_AVAILABLE = ('ok_cancel_dialog' in dir(sublime))
DIFF_IS_AVAILABLE = ('reset_reference_document' in dir(sublime.View))

ENCODINGS_NAME = []
ENCODINGS_CODE = []
Expand Down Expand Up @@ -138,6 +139,7 @@ def get_settings():
SETTINGS['lazy_reload'] = settings.get('lazy_reload', True)
SETTINGS['convert_on_find'] = settings.get('convert_on_find', False)
SETTINGS['confidence'] = settings.get('confidence', 0.95)
SETTINGS['reset_diff_markers'] = settings.get('reset_diff_markers', True)

def get_setting(view, key):
# read project specific settings first
Expand Down Expand Up @@ -468,6 +470,9 @@ def run(self, edit, encoding=None, stamp=None, detect_on_fail=False):
vp = view.viewport_position()
view.set_viewport_position((0, 0), False)
view.replace(edit, regions, contents)
if DIFF_IS_AVAILABLE and get_setting(view, 'reset_diff_markers'):
view.reset_reference_document()
view.settings().set('origin_content', contents)
sel.clear()
for x in rs:
sel.add(self.find_region(x))
Expand Down Expand Up @@ -800,6 +805,8 @@ def undo_me(self, view):
# 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)
if DIFF_IS_AVAILABLE and get_setting(view, 'reset_diff_markers'):
view.set_reference_document(view.settings().get('origin_content'))

def on_deactivated(self, view):
# st2 will reload file when on_deactivated
Expand Down
3 changes: 3 additions & 0 deletions ConvertToUTF8.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
["UTF-8", "UTF-8"]
],

// Reset diff markers after converting
"reset_diff_markers" : true,

// Maximum size for encoding cache, 0 means no cache
"max_cache_size" : 100,

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ Configuration
Please check ConvertToUTF8.sublime-settings file for details. You should save your personal settings in a file named "ConvertToUTF8.sublime-settings" under "User" folder. You can set project-specific settings (except encoding_list and max_cache_size) in the .sublime-project file which can be opened via "Project > Edit Project" menu.

* encoding_list: encoding selection list when detection is failed
* reset_diff_markers: reset diff markers after converting (default: true)
* max_cache_size: maximum encoding cache size, 0 means no cache (default: 100)
* max_detect_lines: maximum detection lines, 0 means unlimited (default: 600)
* preview_action: converting the file's content to UTF-8 when previewing it (default: false)
* preview_action: convert the file's content to UTF-8 when previewing it (default: false)
* default_encoding_on_create: specific the default encoding for newly created file (such as "GBK"), empty value means using sublime text's "default_encoding" setting (default: "")
* convert_on_load: convert the file's content to UTF-8 when it is loaded (default: true)
* convert_on_save: convert the file's content from UTF-8 to its original (or specific) encoding when it is saved (default: true)
* convert_on_find: convert the text in Find Results view to UTF-8 (default: false)
* lazy_reload: save file to a temporary location, and reload it in background when switching to other windows or tabs (default: false)
* confidence: The minimum confidence rate which the converting will be performed automatic. (default: 0.95)
* confidence: the minimum confidence rate which the converting will be performed automatic. (default: 0.95)

Usage
------------------
Expand Down
1 change: 1 addition & 0 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
请查看 ConvertToUTF8.sublime-settings 文件获取详细信息。为防止更新插件时被覆盖,请将个人设置保存到 User 目录中名为 ConvertToUTF8.sublime-settings 文件中。您可以在 .sublime-project 文件(可通过 Project > Edit Project 打开)中指定项目专属设置(除 encoding_list 和 max_cache_size 外)。

* encoding_list:检测失败时显示的编码列表
* reset_diff_markers:在转换后重置差异标记(默认为 true)
* max_cache_size:最大编码缓存数量,0 表示不缓存(默认为 100)
* max_detect_lines:最大检测行数,0 表示不限制(默认为 600)
* preview_action:预览文件时是否将其内容转换为 UTF-8(默认为 false)
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.13": "messages/1.2.13.txt",
"1.2.12": "messages/1.2.12.txt",
"1.2.11": "messages/1.2.11.txt",
"1.2.10": "messages/1.2.10.txt",
Expand Down
4 changes: 4 additions & 0 deletions messages/1.2.13.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ConvertToUTF8 1.2.13 Changelog

New Features
- Added "reset_diff_markers" setting for resetting the diff markers in the gutter (defaults to true)

0 comments on commit 1c6c2ac

Please sign in to comment.