@@ -76,8 +76,9 @@ extension BBCodeExt on BBCodeEditorController {
7676 /// Insert [text] into current cursor position and format with [attr] .
7777 void insertFormattedText (String text, Attribute <dynamic > attr) {
7878 final position = selection.baseOffset;
79+ final length = selection.extentOffset - position;
7980 this
80- ..replaceText (position, text. length, text, null )
81+ ..replaceText (position, length, text, null )
8182 ..formatText (position, text.length, attr)
8283 ..moveCursorToPosition (position + text.length);
8384 }
@@ -86,18 +87,20 @@ extension BBCodeExt on BBCodeEditorController {
8687 /// position between them after insertion.
8788 void insertRawCode (String head, String tail) {
8889 final position = selection.baseOffset;
90+ final length = selection.extentOffset - position;
8991 this
90- ..replaceText (position, head.length + tail. length, head + tail, null )
92+ ..replaceText (position, length, head + tail, null )
9193 ..moveCursorToPosition (position + head.length);
9294 }
9395
9496 /// Insert formatted embed block [embed] into editor.
9597 void insertEmbedBlock (CustomBlockEmbed embed) {
9698 final position = selection.baseOffset;
99+ final length = selection.extentOffset - position;
97100 this
98101 ..replaceText (
99102 position,
100- position ,
103+ length ,
101104 BlockEmbed .custom (embed),
102105 null ,
103106 )
@@ -112,10 +115,11 @@ extension BBCodeExt on BBCodeEditorController {
112115 /// refer: https://github.com/singerdmx/flutter-quill/issues/2303
113116 void insertEmbeddable (Embeddable embed) {
114117 final position = selection.baseOffset;
118+ final length = selection.extentOffset - position;
115119 this
116120 ..replaceText (
117121 position,
118- position ,
122+ length ,
119123 embed,
120124 null ,
121125 )
0 commit comments