Skip to content

Commit e537b89

Browse files
committed
feat: add api to insert plain text without formatting
1 parent 7867850 commit e537b89

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

lib/src/editor_controller.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ extension BBCodeExt on BBCodeEditorController {
9898
return trimCR ? data.replaceAll('\r', '') : data;
9999
}
100100

101+
/// Insert plain [text] into current cursor position, no formatting, no attributes.
102+
void insertPlainText(String text, {bool trimCR = true}) {
103+
final data = switch (trimCR) {
104+
true => text.replaceAll('\r', ''),
105+
false => text,
106+
};
107+
final position = selection.baseOffset;
108+
final length = selection.extentOffset - position;
109+
this
110+
..replaceText(position, length, data, null)
111+
..moveCursorToPosition(position + data.length);
112+
}
113+
101114
/// Insert [text] into current cursor position and format with [attr].
102115
void insertFormattedText(String text, Attribute<dynamic> attr, {bool trimCR = true}) {
103116
final data = switch (trimCR) {

0 commit comments

Comments
 (0)