mirror of
https://github.com/hexedtech/codemp-sublime.git
synced 2025-03-29 21:01:34 +01:00
fix: now when joining a buffer the text is correctly loaded and the syntax is assigned
This commit is contained in:
parent
8e6e9e07a1
commit
db033e7882
2 changed files with 14 additions and 19 deletions
plugin
|
@ -18,7 +18,7 @@ class CodempJoinBufferCommand(sublime_plugin.WindowCommand):
|
||||||
return len(workspaces.lookup(self.window)) > 0
|
return len(workspaces.lookup(self.window)) > 0
|
||||||
|
|
||||||
def input_description(self) -> str:
|
def input_description(self) -> str:
|
||||||
return "Attach: "
|
return "Join Buffer: "
|
||||||
|
|
||||||
def input(self, args):
|
def input(self, args):
|
||||||
if "workspace_id" not in args:
|
if "workspace_id" not in args:
|
||||||
|
@ -46,8 +46,8 @@ class CodempJoinBufferCommand(sublime_plugin.WindowCommand):
|
||||||
|
|
||||||
try: # if it exists already, focus and listen
|
try: # if it exists already, focus and listen
|
||||||
buff = buffers.lookupId(buffer_id)
|
buff = buffers.lookupId(buffer_id)
|
||||||
safe_listener_detach(TEXT_LISTENER)
|
# safe_listener_detach(TEXT_LISTENER)
|
||||||
safe_listener_attach(TEXT_LISTENER, buff.view.buffer())
|
# safe_listener_attach(TEXT_LISTENER, buff.view.buffer())
|
||||||
self.window.focus_view(buff.view)
|
self.window.focus_view(buff.view)
|
||||||
return
|
return
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -66,17 +66,10 @@ class CodempJoinBufferCommand(sublime_plugin.WindowCommand):
|
||||||
sublime.error_message(f"Could not attach to buffer '{buffer_id}'")
|
sublime.error_message(f"Could not attach to buffer '{buffer_id}'")
|
||||||
return
|
return
|
||||||
|
|
||||||
safe_listener_detach(TEXT_LISTENER)
|
|
||||||
content_promise = buff_ctl.content()
|
|
||||||
vbuff = buffers.register(buff_ctl, vws)
|
|
||||||
|
|
||||||
content = content_promise.wait()
|
vbuff = buffers.register(buff_ctl, vws)
|
||||||
populate_view(vbuff.view, content)
|
vbuff.sync(TEXT_LISTENER)
|
||||||
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)
|
|
||||||
sublime.set_timeout_async(_)
|
sublime.set_timeout_async(_)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -143,16 +143,18 @@ class BufferRegistry():
|
||||||
|
|
||||||
def register(self, bhandle: codemp.BufferController, wsm: WorkspaceManager):
|
def register(self, bhandle: codemp.BufferController, wsm: WorkspaceManager):
|
||||||
bid = bhandle.path()
|
bid = bhandle.path()
|
||||||
# tmpfile = os.path.join(wsm.rootdir, bid)
|
|
||||||
# open(tmpfile, "a").close()
|
|
||||||
|
|
||||||
win = sublime.active_window()
|
win = sublime.active_window()
|
||||||
view = win.open_file(bid)
|
newfileflags = sublime.NewFileFlags.TRANSIENT | sublime.NewFileFlags.ADD_TO_SELECTION | sublime.NewFileFlags.FORCE_CLONE
|
||||||
while view.is_loading():
|
view = win.new_file(newfileflags)
|
||||||
pass # yes spinlock, fite me.
|
|
||||||
|
|
||||||
view.set_scratch(True)
|
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_VIEW_TAG, True)
|
||||||
view.settings().set(g.CODEMP_BUFFER_ID, bid)
|
view.settings().set(g.CODEMP_BUFFER_ID, bid)
|
||||||
view.set_status(g.SUBLIME_STATUS_ID, "[Codemp]")
|
view.set_status(g.SUBLIME_STATUS_ID, "[Codemp]")
|
||||||
|
|
Loading…
Add table
Reference in a new issue