From 22dee88e51603ba64eff45370cb4194b927afff3 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 26 Apr 2025 19:25:05 -0600 Subject: [PATCH] Refactor code editor completion logic to use explicit from/to parameters for insertion and selection handling --- .../dokploy/components/shared/code-editor.tsx | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/apps/dokploy/components/shared/code-editor.tsx b/apps/dokploy/components/shared/code-editor.tsx index d8eeffe55..23e26e887 100644 --- a/apps/dokploy/components/shared/code-editor.tsx +++ b/apps/dokploy/components/shared/code-editor.tsx @@ -26,15 +26,20 @@ const dockerComposeServices = [ { label: "secrets", type: "keyword", info: "Define secrets" }, ].map((opt) => ({ ...opt, - apply: (view: EditorView, completion: Completion) => { + apply: ( + view: EditorView, + completion: Completion, + from: number, + to: number, + ) => { const insert = `${completion.label}:`; view.dispatch({ changes: { - from: view.state.selection.main.from, - to: view.state.selection.main.to, + from, + to, insert, }, - selection: { anchor: view.state.selection.main.from + insert.length }, + selection: { anchor: from + insert.length }, }); }, })); @@ -74,15 +79,20 @@ const dockerComposeServiceOptions = [ { label: "networks", type: "keyword", info: "Networks to join" }, ].map((opt) => ({ ...opt, - apply: (view: EditorView, completion: Completion) => { + apply: ( + view: EditorView, + completion: Completion, + from: number, + to: number, + ) => { const insert = `${completion.label}: `; view.dispatch({ changes: { - from: view.state.selection.main.from, - to: view.state.selection.main.to, + from, + to, insert, }, - selection: { anchor: view.state.selection.main.from + insert.length }, + selection: { anchor: from + insert.length }, }); }, })); @@ -99,6 +109,7 @@ function dockerComposeComplete( const line = context.state.doc.lineAt(context.pos); const indentation = /^\s*/.exec(line.text)?.[0].length || 0; + // If we're at the root level if (indentation === 0) { return { from: word.from,