fix: now when joining a buffer the text is correctly loaded and the syntax is assigned

This commit is contained in:
cschen 2025-02-15 22:21:48 +01:00
parent 8e6e9e07a1
commit db033e7882
2 changed files with 14 additions and 19 deletions
plugin

View file

@ -18,7 +18,7 @@ class CodempJoinBufferCommand(sublime_plugin.WindowCommand):
return len(workspaces.lookup(self.window)) > 0
def input_description(self) -> str:
return "Attach: "
return "Join Buffer: "
def input(self, args):
if "workspace_id" not in args:
@ -46,8 +46,8 @@ class CodempJoinBufferCommand(sublime_plugin.WindowCommand):
try: # if it exists already, focus and listen
buff = buffers.lookupId(buffer_id)
safe_listener_detach(TEXT_LISTENER)
safe_listener_attach(TEXT_LISTENER, buff.view.buffer())
# safe_listener_detach(TEXT_LISTENER)
# safe_listener_attach(TEXT_LISTENER, buff.view.buffer())
self.window.focus_view(buff.view)
return
except KeyError:
@ -66,17 +66,10 @@ class CodempJoinBufferCommand(sublime_plugin.WindowCommand):
sublime.error_message(f"Could not attach to buffer '{buffer_id}'")
return
safe_listener_detach(TEXT_LISTENER)
content_promise = buff_ctl.content()
vbuff = buffers.register(buff_ctl, vws)
content = content_promise.wait()
populate_view(vbuff.view, content)
if self.window.active_view() == vbuff.view:
# if view is already active, focusing it won't trigger `on_activate`.
safe_listener_attach(TEXT_LISTENER, vbuff.view.buffer())
else:
self.window.focus_view(vbuff.view)
vbuff = buffers.register(buff_ctl, vws)
vbuff.sync(TEXT_LISTENER)
sublime.set_timeout_async(_)

View file

@ -143,16 +143,18 @@ class BufferRegistry():
def register(self, bhandle: codemp.BufferController, wsm: WorkspaceManager):
bid = bhandle.path()
# tmpfile = os.path.join(wsm.rootdir, bid)
# open(tmpfile, "a").close()
win = sublime.active_window()
view = win.open_file(bid)
while view.is_loading():
pass # yes spinlock, fite me.
newfileflags = sublime.NewFileFlags.TRANSIENT | sublime.NewFileFlags.ADD_TO_SELECTION | sublime.NewFileFlags.FORCE_CLONE
view = win.new_file(newfileflags)
view.set_scratch(True)
# view.retarget(tmpfile)
view.set_name(os.path.basename(bid))
syntax = sublime.find_syntax_for_file(bid)
if syntax:
view.assign_syntax(syntax)
view.settings().set(g.CODEMP_VIEW_TAG, True)
view.settings().set(g.CODEMP_BUFFER_ID, bid)
view.set_status(g.SUBLIME_STATUS_ID, "[Codemp]")