From 10781f2a5e4f57ffc66bf59e5398fff956a2d01c Mon Sep 17 00:00:00 2001 From: Demizo Date: Sat, 7 Mar 2026 12:24:25 -0600 Subject: [PATCH] feat: insert templates at cursor position --- lib/widgets/edit_toolbar.dart | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/widgets/edit_toolbar.dart b/lib/widgets/edit_toolbar.dart index e996e254..b5890091 100644 --- a/lib/widgets/edit_toolbar.dart +++ b/lib/widgets/edit_toolbar.dart @@ -25,8 +25,18 @@ class EditToolbar extends StatelessWidget { builder: (BuildContext context) { return TemplateSelect( onTemplatesSelected: (Template template) { + final templateText = template.text ?? ""; if (controller.text.isNotEmpty) { - controller.text += "\n${template.text ?? ""}"; + if (controller.selection.isValid) { + int cursorPos = controller.selection.base.offset; + final beforeText = controller.text.substring(0, cursorPos); + final afterText = controller.text.substring(cursorPos); + controller.text = beforeText + templateText + afterText; + controller.selection = TextSelection.collapsed( + offset: cursorPos + templateText.length); + } else { + controller.text += "\n${template.text ?? ""}"; + } } else { controller.text = template.text ?? ""; }