mirror of
https://github.com/hexedtech/codemp-sublime.git
synced 2024-11-22 06:44:48 +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():
|
while cursor_event := await cursor_controller.recv():
|
||||||
buffer = get_buffer_from_remote_name(cursor_event.buffer)
|
buffer = get_buffer_from_remote_name(cursor_event.buffer)
|
||||||
|
|
||||||
if buffer:
|
if not buffer:
|
||||||
reg = rowcol_to_region(buffer.view, cursor_event.start, cursor_event.end)
|
status_log("Received a cursor event for an unknown buffer: {}".format(cursor_event.buffer))
|
||||||
# reg_flags = sublime.RegionFlags.DRAW_EMPTY | sublime.RegionFlags.DRAW_NO_FILL
|
continue
|
||||||
reg_flags = sublime.RegionFlags.DRAW_EMPTY
|
|
||||||
|
|
||||||
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(
|
user_hash = hash(cursor_event.user)
|
||||||
"codemp-cursors-{}".format(user_hash),
|
|
||||||
[reg],
|
buffer.view.add_regions(
|
||||||
flags = reg_flags,
|
"codemp-cursors-{}".format(user_hash),
|
||||||
scope=_regions_colors[user_hash % len(_regions_colors)],
|
[reg],
|
||||||
annotations = [cursor_event.user],
|
flags = reg_flags,
|
||||||
annotation_color=_palette[user_hash % len(_palette)]
|
scope=_regions_colors[user_hash % len(_regions_colors)],
|
||||||
)
|
annotations = [cursor_event.user],
|
||||||
|
annotation_color=_palette[user_hash % len(_palette)]
|
||||||
|
)
|
||||||
|
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
status_log("cursor worker stopped...")
|
status_log("cursor worker stopped...")
|
||||||
|
@ -327,8 +329,6 @@ async def join_buffer_command(view, remote_name):
|
||||||
global _client
|
global _client
|
||||||
global _buffers
|
global _buffers
|
||||||
|
|
||||||
# print(await _client.select_buffer())
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
buffer = CodempSublimeBuffer(view, remote_name)
|
buffer = CodempSublimeBuffer(view, remote_name)
|
||||||
await buffer.attach(_client)
|
await buffer.attach(_client)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import Codemp.bindings.codemp_client as libcodemp
|
import Codemp.bindings.codemp_client as libcodemp
|
||||||
|
|
||||||
|
# These are helper wrappers, not very interesting
|
||||||
|
|
||||||
class CodempClient():
|
class CodempClient():
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -33,19 +35,12 @@ class CodempClient():
|
||||||
async def select_buffer(self): # -> String
|
async def select_buffer(self): # -> String
|
||||||
await self.handle.select_buffer()
|
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():
|
class CursorController():
|
||||||
def __init__(self, handle):
|
def __init__(self, handle):
|
||||||
self.handle = handle
|
self.handle = handle
|
||||||
|
|
||||||
def send(self, path, start, end): # -> None
|
def send(self, buffer_id, start, end): # -> None
|
||||||
self.handle.send(path, start, end)
|
self.handle.send(buffer_id, start, end)
|
||||||
|
|
||||||
def try_recv(self): # -> Optional[CursorEvent]
|
def try_recv(self): # -> Optional[CursorEvent]
|
||||||
return self.handle.try_recv()
|
return self.handle.try_recv()
|
||||||
|
|
Loading…
Reference in a new issue