From db033e78822b60b2f436f449c5b405a8075657a1 Mon Sep 17 00:00:00 2001 From: cschen <camillo.schenone@gmail.com> Date: Sat, 15 Feb 2025 22:21:48 +0100 Subject: [PATCH] fix: now when joining a buffer the text is correctly loaded and the syntax is assigned --- plugin/commands/workspace.py | 19 ++++++------------- plugin/core/buffers.py | 14 ++++++++------ 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/plugin/commands/workspace.py b/plugin/commands/workspace.py index 8ac28fb..8862f1d 100644 --- a/plugin/commands/workspace.py +++ b/plugin/commands/workspace.py @@ -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(_) diff --git a/plugin/core/buffers.py b/plugin/core/buffers.py index aea1e95..04c8f04 100644 --- a/plugin/core/buffers.py +++ b/plugin/core/buffers.py @@ -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]")