fregante / GhostText

👻 Use your text editor to write in your browser. Everything you type in the editor will be instantly updated in the browser (and vice versa).
https://GhostText.fregante.com
MIT License
3.25k stars 116 forks source link

Sublime Text echoes the same received text #180

Closed fregante closed 1 year ago

fregante commented 3 years ago

This happens in any field in any browser. ST responds with the same data as soon as you type something in the browser

https://ghosttext.github.io/GhostText/demo/

This issue is currently avoided by ignoring any updates from the editor when the browser is focused, but it should still be fixed in Sublime Text.

subnut commented 3 years ago

GhostText.py

+do_not_respond = False

...

     def on_message(self, text):
+    global do_not_respond
+    do_not_respond = True
         try:
             request = json.loads(text)
             self._current_view.run_command('replace_content', request)
             self._current_view.window().focus_view(self._current_view)
         except ValueError as e:
             Utils.show_error(e, 'Invalid JSON')
+        finally:
+             do_not_respond = False
....

GhostTextTools/OnSelectionModifiedListener.py

...

     def on_selection_modified(self, view):
         if view.id() not in OnSelectionModifiedListener._bind_views:
             return
+        global do_not_respond
+        if do_not_respond:
+            return

...

It should™ solve the issue

fregante commented 3 years ago

I will™ try it once the stores accept the latest version

fregante commented 3 years ago

Can you open a PR on https://github.com/GhostText/GhostText-for-SublimeText?

subnut commented 3 years ago

I tried it, it doesn't work :disappointed:

subnut commented 3 years ago

Can you please grant me push access to that repo? I will do my changes in a new branch. If the code seems OK, and I am able to understand how sublime plugins work, I will take up the responsibility of maintaining that plugin.

fregante commented 3 years ago

You can submit a regular PR and merge it once it works

kaste commented 1 year ago

I made a PR ☝️ https://github.com/GhostText/GhostText-for-SublimeText/pull/2 👈

fregante commented 1 year ago

Confirmed to be fixed in v1.0.15

Thanks @kaste!