Fix: Ignore cursor events for unknown buffers, print a warn

Former-commit-id: fb53518d4bba645283edcf349ce9eda9dc081b7d
This commit is contained in:
Camillo Schenone 2023-12-18 22:09:24 +01:00
parent 5e1c0e597f
commit 2d8fb97166
2 changed files with 19 additions and 24 deletions

View file

@ -178,10 +178,12 @@ async def move_cursor(cursor_controller):
while cursor_event := await cursor_controller.recv():
buffer = get_buffer_from_remote_name(cursor_event.buffer)
if buffer:
if not buffer:
status_log("Received a cursor event for an unknown buffer: {}".format(cursor_event.buffer))
continue
reg = rowcol_to_region(buffer.view, cursor_event.start, cursor_event.end)
# reg_flags = sublime.RegionFlags.DRAW_EMPTY | sublime.RegionFlags.DRAW_NO_FILL
reg_flags = sublime.RegionFlags.DRAW_EMPTY
reg_flags = sublime.RegionFlags.DRAW_EMPTY # show cursors.
user_hash = hash(cursor_event.user)
@ -327,8 +329,6 @@ async def join_buffer_command(view, remote_name):
global _client
global _buffers
# print(await _client.select_buffer())
try:
buffer = CodempSublimeBuffer(view, remote_name)
await buffer.attach(_client)

View file

@ -1,6 +1,8 @@
import asyncio
import Codemp.bindings.codemp_client as libcodemp
# These are helper wrappers, not very interesting
class CodempClient():
def __init__(self):
@ -33,19 +35,12 @@ class CodempClient():
async def select_buffer(self): # -> String
await self.handle.select_buffer()
## Custom
async def disconnect(self): # -> None
# disconnect all buffers and workspaces first, maybe?
await self.leave_workspace()
# drop the handle, it will require a new instantiation
self.handle = None
class CursorController():
def __init__(self, handle):
self.handle = handle
def send(self, path, start, end): # -> None
self.handle.send(path, start, end)
def send(self, buffer_id, start, end): # -> None
self.handle.send(buffer_id, start, end)
def try_recv(self): # -> Optional[CursorEvent]
return self.handle.try_recv()