Created
March 26, 2024 02:52
-
-
Save hyrious/e9aa78400ba13899529afd932c17028f to your computer and use it in GitHub Desktop.
Replace chinese comma "," with ", " seaminglessly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin | |
have_a_rest = False | |
class FixCjkCommaListener(sublime_plugin.TextChangeListener): | |
def on_text_changed(self, changes): | |
global have_a_rest | |
if len(changes) != 1 or have_a_rest: return | |
c = changes[0] | |
if c.str != ',': return | |
i = c.b.pt | |
v = sublime.active_window().active_view() | |
if i and v: | |
have_a_rest = True | |
v.run_command("fix_cjk_comma", { 'pt': i }) | |
class FixCjkComma(sublime_plugin.TextCommand): | |
def run(self, edit, pt=-1): | |
sublime.set_timeout(self.recover, 500) | |
self.view.replace(edit, sublime.Region(pt, pt + 1), ", ") | |
def recover(self): | |
global have_a_rest | |
have_a_rest = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment