diff --git a/plugin.py b/plugin.py index 1eb62ed..ce3ef67 100644 --- a/plugin.py +++ b/plugin.py @@ -178,21 +178,23 @@ async def move_cursor(cursor_controller): while cursor_event := await cursor_controller.recv(): buffer = get_buffer_from_remote_name(cursor_event.buffer) - if buffer: - 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 + if not buffer: + status_log("Received a cursor event for an unknown buffer: {}".format(cursor_event.buffer)) + continue - user_hash = hash(cursor_event.user) + reg = rowcol_to_region(buffer.view, cursor_event.start, cursor_event.end) + reg_flags = sublime.RegionFlags.DRAW_EMPTY # show cursors. - buffer.view.add_regions( - "codemp-cursors-{}".format(user_hash), - [reg], - flags = reg_flags, - scope=_regions_colors[user_hash % len(_regions_colors)], - annotations = [cursor_event.user], - annotation_color=_palette[user_hash % len(_palette)] - ) + user_hash = hash(cursor_event.user) + + buffer.view.add_regions( + "codemp-cursors-{}".format(user_hash), + [reg], + flags = reg_flags, + scope=_regions_colors[user_hash % len(_regions_colors)], + annotations = [cursor_event.user], + annotation_color=_palette[user_hash % len(_palette)] + ) except asyncio.CancelledError: status_log("cursor worker stopped...") @@ -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) diff --git a/src/codemp_client.py b/src/codemp_client.py index 7fc5fe2..8a06ce9 100644 --- a/src/codemp_client.py +++ b/src/codemp_client.py @@ -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()