mirror of
https://github.com/hexedtech/codemp-sublime.git
synced 2024-11-22 06:44:48 +01:00
chore: missed the file with the text change listener class. It was moved in its own file because
this function is crucial and needs some extra attention.
This commit is contained in:
parent
8565356d38
commit
ecd0bf5672
1 changed files with 32 additions and 0 deletions
32
plugin/text_listener.py
Normal file
32
plugin/text_listener.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
import sublime_plugin
|
||||
import logging
|
||||
|
||||
from .core.buffers import buffers
|
||||
from . import globals as g
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class CodempClientTextChangeListener(sublime_plugin.TextChangeListener):
|
||||
@classmethod
|
||||
def is_applicable(cls, _): # pyright: ignore
|
||||
# don't attach this event listener automatically
|
||||
# we'll do it by hand with .attach(buffer).
|
||||
return False
|
||||
|
||||
def on_text_changed(self, changes):
|
||||
s = self.buffer.primary_view().settings()
|
||||
if s.get(g.CODEMP_IGNORE_NEXT_TEXT_CHANGE, False):
|
||||
logger.debug("Ignoring echoing back the change.")
|
||||
s[g.CODEMP_IGNORE_NEXT_TEXT_CHANGE] = False
|
||||
return
|
||||
|
||||
bid = str(s.get(g.CODEMP_BUFFER_ID))
|
||||
try:
|
||||
vbuff = buffers.lookupId(bid)
|
||||
logger.debug(f"local buffer change! {vbuff.id}")
|
||||
vbuff.send_change(changes)
|
||||
except KeyError:
|
||||
logger.error(f"could not find registered buffer with id {bid}")
|
||||
pass
|
||||
|
||||
TEXT_LISTENER = CodempClientTextChangeListener()
|
Loading…
Reference in a new issue