Fix node bool containsOffset(int offset)

pull/13/head
singerdmx 4 years ago
parent e469d8da73
commit b3a43e3da4
  1. 7
      lib/models/documents/nodes/node.dart
  2. 5
      lib/widgets/raw_editor.dart
  3. 5
      lib/widgets/text_block.dart

@ -57,12 +57,13 @@ abstract class Node extends LinkedListEntry<Node> {
}
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

@ -585,7 +585,7 @@ class RawEditorState extends EditorState
result.add(editableTextLine);
} else if (node is Block) {
Map<String, Attribute> 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.');
}

@ -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);
}

Loading…
Cancel
Save