From f01f93590770f0a7a2124efb78516073dbddf5ae Mon Sep 17 00:00:00 2001 From: Miroslav Sobotka Date: Thu, 16 Nov 2023 22:24:25 +0100 Subject: [PATCH] Apply only inline styles for inline (#1539) Co-authored-by: Miroslav Sobotka --- lib/src/models/documents/nodes/line.dart | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/src/models/documents/nodes/line.dart b/lib/src/models/documents/nodes/line.dart index e11f095c..eb6a1744 100644 --- a/lib/src/models/documents/nodes/line.dart +++ b/lib/src/models/documents/nodes/line.dart @@ -317,6 +317,14 @@ base class Line extends Container { void _insertSafe(int index, Object data, Style? style) { assert(index == 0 || (index > 0 && index < length)); + var inlineStyles = style; + if (style != null) { + final nonInlineStyles = + style.attributes.values.where((v) => !v.isInline).toSet(); + final styleToApply = style.removeAll(nonInlineStyles); + inlineStyles = styleToApply; + } + if (data is String) { assert(!data.contains('\n')); if (data.isEmpty) { @@ -327,10 +335,10 @@ base class Line extends Container { if (isEmpty) { final child = Leaf(data); add(child); - child.format(style); + child.format(inlineStyles); } else { final result = queryChild(index, true); - result.node!.insert(result.offset, data, style); + result.node!.insert(result.offset, data, inlineStyles); } }