feat: adds small utility to check if a view is a codemp buffer

This commit is contained in:
cschen 2025-02-15 22:19:42 +01:00
parent 7cd471eb4f
commit 40073be509
3 changed files with 17 additions and 11 deletions

View file

@ -13,12 +13,12 @@
"default": "[\n\t$0\n]\n"
}
},
{ "caption": "Codemp: Open Readme",
"command": "open_file",
"args": {
"file": "${packages}/CodempClient/README.md"
}
},
// { "caption": "Codemp: Open Readme",
// "command": "open_file",
// "args": {
// "file": "${packages}/CodempClient/README.md"
// }
// },
{
"caption": "Codemp: Browse Server",
"command": "codemp_browse_server",
@ -27,9 +27,7 @@
{
"caption": "Codemp: Browse Workspace",
"command": "codemp_browse_workspace",
"args": {
}
"args": {}
},
{
// # on_window_command, does not trigger when called from the command palette

View file

@ -51,7 +51,7 @@ def kill_all():
session.stop()
def vbuff_form_view(view):
if not view.settings().get(g.CODEMP_VIEW_TAG, False):
if not is_codemp_buffer(view):
raise ValueError("The view is not a Codemp Buffer.")
buffid = str(view.settings().get(g.CODEMP_BUFFER_ID))
@ -103,8 +103,11 @@ class CodempReplaceTextCommand(sublime_plugin.TextCommand):
class CodempSyncBuffer(sublime_plugin.TextCommand):
def is_enabled(self) -> bool:
return is_codemp_buffer(self.view)
def run(self, edit):
buff = buffers.lookupId(str(self.view.settings().get(g.CODEMP_BUFFER_ID)))
buff = vbuff_form_view(self.view)
buff.sync(TEXT_LISTENER)

View file

@ -99,6 +99,11 @@ def view_from_local_path(path):
if view.file_name() == path:
return view
def is_codemp_buffer(view):
if view.settings().get(g.CODEMP_VIEW_TAG, False):
return True
else:
return False
def draw_cursor_region(view, start, end, user):
reg = rowcol_to_region(view, start, end)