Skip to content

Instantly share code, notes, and snippets.

@hyrious
Created March 26, 2024 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyrious/e9aa78400ba13899529afd932c17028f to your computer and use it in GitHub Desktop.
Save hyrious/e9aa78400ba13899529afd932c17028f to your computer and use it in GitHub Desktop.
Replace chinese comma "," with ", " seaminglessly.
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