mirror of
https://github.com/hexedtech/codemp-sublime.git
synced 2024-12-23 13:14:52 +01:00
Fix: Ignore cursor events for unknown buffers, print a warn
Former-commit-id: fb53518d4bba645283edcf349ce9eda9dc081b7d
This commit is contained in:
parent
5e1c0e597f
commit
2d8fb97166
2 changed files with 19 additions and 24 deletions
30
plugin.py
30
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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue