From 2ef29c004a409599eedcb0ed5a5d2eb825154740 Mon Sep 17 00:00:00 2001 From: dbin0123 Date: Sat, 13 Jun 2026 11:42:03 +0800 Subject: [PATCH] fix(editor): keep cursor at end of inserted completion text (#1136) Thanks @dbin0123! --- apps/desktop/src/components/editor/QueryEditor.vue | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vue index 2e69401b38..855c3168ac 100644 --- a/apps/desktop/src/components/editor/QueryEditor.vue +++ b/apps/desktop/src/components/editor/QueryEditor.vue @@ -868,7 +868,11 @@ function completionOptionForItem(item: QueryCompletionItem) { if (typeof originalApply === "function") { originalApply(view, completionItem as never, from, to); } else { - view.dispatch({ changes: { from, to, insert: String(originalApply ?? item.label) } }); + const insert = String(originalApply ?? item.label); + view.dispatch({ + changes: { from, to, insert }, + selection: { anchor: from + insert.length }, + }); } }, }; @@ -881,7 +885,11 @@ function completionOptionForItem(item: QueryCompletionItem) { boost: item.boost, apply(view: EditorViewType, _completionItem: unknown, from: number, to: number) { record(); - view.dispatch({ changes: { from, to, insert: item.apply ?? item.label } }); + const insert = item.apply ?? item.label; + view.dispatch({ + changes: { from, to, insert }, + selection: { anchor: from + insert.length }, + }); }, }; }