Skip to content

Commit 300ebed

Browse files
committed
fix: fix paragraph attributes not finished on last paragraph
For the following example BBCode: ``` [code] xxx [/code] ``` the parsed quill delta as a '\n' as the last operation which also have a code-block attribute. It's not added to meet "always ended with '\n'" purpose but to finish the code block paragraph attribute. In previous versions, when `insertBBCode`, the last paragraph would be removed if it only has a '\n', considered as the meet of "always ended with '\n'", we shall not that if the paragraph has paragraph attributes: in this condition, '\n' is to finish the paragraph attribute. This commit added another condition to skip removing the last operation if paragraph has attributes.
1 parent 942e3c2 commit 300ebed

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/src/editor_controller.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ extension BBCodeExt on BBCodeEditorController {
182182
// Remove the trailing space because the space may be added by editor not user.
183183
// Note that if user manually ends the text with '\n', we can not tell if the trailing '\n' is inserted by editor
184184
// or not, this issue occurs everywhere we process text content.
185-
if (lastOp.data != null && lastOp.data is String) {
185+
//
186+
// Do not remove the trailing '\n' if the operation has attribute: where it's definitely not added by editor for
187+
// format purpose.
188+
if ((lastOp.attributes?.isEmpty ?? true) && lastOp.data != null && lastOp.data is String) {
186189
final lastOpStr = lastOp.data! as String;
187190
if (lastOpStr.length == 1 && lastOpStr.endsWith('\n')) {
188191
delta = Delta.fromOperations(List.from(delta.operations)..removeLast());

0 commit comments

Comments
 (0)