From b3a43e3da47084471ba79bfde7e341f0b455183b Mon Sep 17 00:00:00 2001 From: singerdmx Date: Tue, 22 Dec 2020 05:50:13 -0800 Subject: [PATCH] Fix node bool containsOffset(int offset) --- lib/models/documents/nodes/node.dart | 7 ++++--- lib/widgets/raw_editor.dart | 5 +++-- lib/widgets/text_block.dart | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/models/documents/nodes/node.dart b/lib/models/documents/nodes/node.dart index 91d59687..cf74324b 100644 --- a/lib/models/documents/nodes/node.dart +++ b/lib/models/documents/nodes/node.dart @@ -57,12 +57,13 @@ abstract class Node extends LinkedListEntry { } int getDocumentOffset() { - return parent is! Root ? parent.getDocumentOffset() : 0 + getOffset(); + final parentOffset = (parent is! Root) ? parent.getDocumentOffset() : 0; + return parentOffset + getOffset(); } bool containsOffset(int offset) { - return getDocumentOffset() <= offset && - offset < getDocumentOffset() + this.length; + final o = getDocumentOffset(); + return o <= offset && offset < o + length; } @override diff --git a/lib/widgets/raw_editor.dart b/lib/widgets/raw_editor.dart index c3f47320..3d944e0d 100644 --- a/lib/widgets/raw_editor.dart +++ b/lib/widgets/raw_editor.dart @@ -585,7 +585,7 @@ class RawEditorState extends EditorState result.add(editableTextLine); } else if (node is Block) { Map attrs = node.style.attributes; - result.add(EditableTextBlock( + EditableTextBlock editableTextBlock = EditableTextBlock( node, _textDirection, _getVerticalSpacingForBlock(node, _styles), @@ -597,7 +597,8 @@ class RawEditorState extends EditorState ? EdgeInsets.all(16.0) : null, widget.embedBuilder, - _cursorCont)); + _cursorCont); + result.add(editableTextBlock); } else { throw StateError('Unreachable.'); } diff --git a/lib/widgets/text_block.dart b/lib/widgets/text_block.dart index d9cf20b0..f3683f9d 100644 --- a/lib/widgets/text_block.dart +++ b/lib/widgets/text_block.dart @@ -75,7 +75,7 @@ class EditableTextBlock extends StatelessWidget { int index = 0; for (Line line in block.children) { index++; - children.add(EditableTextLine( + EditableTextLine editableTextLine = EditableTextLine( line, _buildLeading(context, line, index, count), TextLine( @@ -91,7 +91,8 @@ class EditableTextBlock extends StatelessWidget { enableInteractiveSelection, hasFocus, MediaQuery.of(context).devicePixelRatio, - cursorCont)); + cursorCont); + children.add(editableTextLine); } return children.toList(growable: false); }