Update RenderEditableBox Container get container

pull/587/head
X Code 3 years ago
parent ce01abfbc5
commit 4f7cc55b42
  1. 2
      lib/src/widgets/box.dart
  2. 50
      lib/src/widgets/editor.dart
  3. 53
      lib/src/widgets/text_block.dart
  4. 10
      lib/src/widgets/text_line.dart

@ -38,7 +38,7 @@ abstract class RenderContentProxyBox implements RenderBox {
/// [RenderContentProxyBox]. /// [RenderContentProxyBox].
abstract class RenderEditableBox extends RenderBox { abstract class RenderEditableBox extends RenderBox {
/// The document node represented by this render box. /// The document node represented by this render box.
Container getContainer(); Container get container;
/// Returns preferred line height at specified `position` in text. /// Returns preferred line height at specified `position` in text.
/// ///

@ -994,7 +994,7 @@ class RenderEditor extends RenderEditableContainerBox
if (textSelection.isCollapsed) { if (textSelection.isCollapsed) {
final child = childAtPosition(textSelection.extent); final child = childAtPosition(textSelection.extent);
final localPosition = TextPosition( final localPosition = TextPosition(
offset: textSelection.extentOffset - child.getContainer().offset); offset: textSelection.extentOffset - child.container.offset);
final localOffset = child.getOffsetForCaret(localPosition); final localOffset = child.getOffsetForCaret(localPosition);
final parentData = child.parentData as BoxParentData; final parentData = child.parentData as BoxParentData;
return <TextSelectionPoint>[ return <TextSelectionPoint>[
@ -1010,7 +1010,7 @@ class RenderEditor extends RenderEditableContainerBox
var baseChild = firstChild; var baseChild = firstChild;
while (baseChild != null) { while (baseChild != null) {
if (baseChild.getContainer() == baseNode) { if (baseChild.container == baseNode) {
break; break;
} }
baseChild = childAfter(baseChild); baseChild = childAfter(baseChild);
@ -1019,7 +1019,7 @@ class RenderEditor extends RenderEditableContainerBox
final baseParentData = baseChild!.parentData as BoxParentData; final baseParentData = baseChild!.parentData as BoxParentData;
final baseSelection = final baseSelection =
localSelection(baseChild.getContainer(), textSelection, true); localSelection(baseChild.container, textSelection, true);
var basePoint = baseChild.getBaseEndpointForSelection(baseSelection); var basePoint = baseChild.getBaseEndpointForSelection(baseSelection);
basePoint = TextSelectionPoint( basePoint = TextSelectionPoint(
basePoint.point + baseParentData.offset, basePoint.direction); basePoint.point + baseParentData.offset, basePoint.direction);
@ -1027,7 +1027,7 @@ class RenderEditor extends RenderEditableContainerBox
final extentNode = _container.queryChild(textSelection.end, false).node; final extentNode = _container.queryChild(textSelection.end, false).node;
RenderEditableBox? extentChild = baseChild; RenderEditableBox? extentChild = baseChild;
while (extentChild != null) { while (extentChild != null) {
if (extentChild.getContainer() == extentNode) { if (extentChild.container == extentNode) {
break; break;
} }
extentChild = childAfter(extentChild); extentChild = childAfter(extentChild);
@ -1036,7 +1036,7 @@ class RenderEditor extends RenderEditableContainerBox
final extentParentData = extentChild!.parentData as BoxParentData; final extentParentData = extentChild!.parentData as BoxParentData;
final extentSelection = final extentSelection =
localSelection(extentChild.getContainer(), textSelection, true); localSelection(extentChild.container, textSelection, true);
var extentPoint = var extentPoint =
extentChild.getExtentEndpointForSelection(extentSelection); extentChild.getExtentEndpointForSelection(extentSelection);
extentPoint = TextSelectionPoint( extentPoint = TextSelectionPoint(
@ -1146,7 +1146,7 @@ class RenderEditor extends RenderEditableContainerBox
assert(_lastTapDownPosition != null); assert(_lastTapDownPosition != null);
final position = getPositionForOffset(_lastTapDownPosition!); final position = getPositionForOffset(_lastTapDownPosition!);
final child = childAtPosition(position); final child = childAtPosition(position);
final nodeOffset = child.getContainer().offset; final nodeOffset = child.container.offset;
final localPosition = TextPosition( final localPosition = TextPosition(
offset: position.offset - nodeOffset, offset: position.offset - nodeOffset,
affinity: position.affinity, affinity: position.affinity,
@ -1335,7 +1335,7 @@ class RenderEditor extends RenderEditableContainerBox
double preferredLineHeight(TextPosition position) { double preferredLineHeight(TextPosition position) {
final child = childAtPosition(position); final child = childAtPosition(position);
return child.preferredLineHeight( return child.preferredLineHeight(
TextPosition(offset: position.offset - child.getContainer().offset)); TextPosition(offset: position.offset - child.container.offset));
} }
@override @override
@ -1347,7 +1347,7 @@ class RenderEditor extends RenderEditableContainerBox
final localOffset = local - parentData.offset; final localOffset = local - parentData.offset;
final localPosition = child.getPositionForOffset(localOffset); final localPosition = child.getPositionForOffset(localOffset);
return TextPosition( return TextPosition(
offset: localPosition.offset + child.getContainer().offset, offset: localPosition.offset + child.container.offset,
affinity: localPosition.affinity, affinity: localPosition.affinity,
); );
} }
@ -1380,8 +1380,7 @@ class RenderEditor extends RenderEditableContainerBox
final caretTop = endpoint.point.dy - final caretTop = endpoint.point.dy -
child.preferredLineHeight(TextPosition( child.preferredLineHeight(TextPosition(
offset: offset: selection.extentOffset - child.container.documentOffset)) -
selection.extentOffset - child.getContainer().documentOffset)) -
kMargin + kMargin +
offsetInViewport + offsetInViewport +
scrollBottomInset; scrollBottomInset;
@ -1540,7 +1539,7 @@ class RenderEditor extends RenderEditableContainerBox
@override @override
TextSelection getLineAtOffset(TextPosition position) { TextSelection getLineAtOffset(TextPosition position) {
final child = childAtPosition(position); final child = childAtPosition(position);
final nodeOffset = child.getContainer().offset; final nodeOffset = child.container.offset;
final localPosition = TextPosition( final localPosition = TextPosition(
offset: position.offset - nodeOffset, affinity: position.affinity); offset: position.offset - nodeOffset, affinity: position.affinity);
final localLineRange = child.getLineBoundary(localPosition); final localLineRange = child.getLineBoundary(localPosition);
@ -1554,7 +1553,7 @@ class RenderEditor extends RenderEditableContainerBox
@override @override
TextRange getWordBoundary(TextPosition position) { TextRange getWordBoundary(TextPosition position) {
final child = childAtPosition(position); final child = childAtPosition(position);
final nodeOffset = child.getContainer().offset; final nodeOffset = child.container.offset;
final localPosition = TextPosition( final localPosition = TextPosition(
offset: position.offset - nodeOffset, affinity: position.affinity); offset: position.offset - nodeOffset, affinity: position.affinity);
final localWord = child.getWordBoundary(localPosition); final localWord = child.getWordBoundary(localPosition);
@ -1571,8 +1570,8 @@ class RenderEditor extends RenderEditableContainerBox
@override @override
TextPosition getTextPositionAbove(TextPosition position) { TextPosition getTextPositionAbove(TextPosition position) {
final child = childAtPosition(position); final child = childAtPosition(position);
final localPosition = TextPosition( final localPosition =
offset: position.offset - child.getContainer().documentOffset); TextPosition(offset: position.offset - child.container.documentOffset);
var newPosition = child.getPositionAbove(localPosition); var newPosition = child.getPositionAbove(localPosition);
@ -1586,18 +1585,16 @@ class RenderEditor extends RenderEditableContainerBox
newPosition = const TextPosition(offset: 0); newPosition = const TextPosition(offset: 0);
} else { } else {
final caretOffset = child.getOffsetForCaret(localPosition); final caretOffset = child.getOffsetForCaret(localPosition);
final testPosition = final testPosition = TextPosition(offset: sibling.container.length - 1);
TextPosition(offset: sibling.getContainer().length - 1);
final testOffset = sibling.getOffsetForCaret(testPosition); final testOffset = sibling.getOffsetForCaret(testPosition);
final finalOffset = Offset(caretOffset.dx, testOffset.dy); final finalOffset = Offset(caretOffset.dx, testOffset.dy);
final siblingPosition = sibling.getPositionForOffset(finalOffset); final siblingPosition = sibling.getPositionForOffset(finalOffset);
newPosition = TextPosition( newPosition = TextPosition(
offset: offset: sibling.container.documentOffset + siblingPosition.offset);
sibling.getContainer().documentOffset + siblingPosition.offset);
} }
} else { } else {
newPosition = TextPosition( newPosition = TextPosition(
offset: child.getContainer().documentOffset + newPosition.offset); offset: child.container.documentOffset + newPosition.offset);
} }
return newPosition; return newPosition;
} }
@ -1609,8 +1606,8 @@ class RenderEditor extends RenderEditableContainerBox
@override @override
TextPosition getTextPositionBelow(TextPosition position) { TextPosition getTextPositionBelow(TextPosition position) {
final child = childAtPosition(position); final child = childAtPosition(position);
final localPosition = TextPosition( final localPosition =
offset: position.offset - child.getContainer().documentOffset); TextPosition(offset: position.offset - child.container.documentOffset);
var newPosition = child.getPositionBelow(localPosition); var newPosition = child.getPositionBelow(localPosition);
@ -1629,12 +1626,11 @@ class RenderEditor extends RenderEditableContainerBox
final finalOffset = Offset(caretOffset.dx, testOffset.dy); final finalOffset = Offset(caretOffset.dx, testOffset.dy);
final siblingPosition = sibling.getPositionForOffset(finalOffset); final siblingPosition = sibling.getPositionForOffset(finalOffset);
newPosition = TextPosition( newPosition = TextPosition(
offset: offset: sibling.container.documentOffset + siblingPosition.offset);
sibling.getContainer().documentOffset + siblingPosition.offset);
} }
} else { } else {
newPosition = TextPosition( newPosition = TextPosition(
offset: child.getContainer().documentOffset + newPosition.offset); offset: child.container.documentOffset + newPosition.offset);
} }
return newPosition; return newPosition;
} }
@ -1679,9 +1675,7 @@ class RenderEditableContainerBox extends RenderBox
double scrollBottomInset; double scrollBottomInset;
EdgeInsets? _resolvedPadding; EdgeInsets? _resolvedPadding;
container_node.Container getContainer() { container_node.Container get container => _container;
return _container;
}
void setContainer(container_node.Container c) { void setContainer(container_node.Container c) {
if (_container == c) { if (_container == c) {
@ -1721,7 +1715,7 @@ class RenderEditableContainerBox extends RenderBox
var targetChild = firstChild; var targetChild = firstChild;
while (targetChild != null) { while (targetChild != null) {
if (targetChild.getContainer() == targetNode) { if (targetChild.container == targetNode) {
break; break;
} }
final newChild = childAfter(targetChild); final newChild = childAfter(targetChild);

@ -349,12 +349,12 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
TextRange getLineBoundary(TextPosition position) { TextRange getLineBoundary(TextPosition position) {
final child = childAtPosition(position); final child = childAtPosition(position);
final rangeInChild = child.getLineBoundary(TextPosition( final rangeInChild = child.getLineBoundary(TextPosition(
offset: position.offset - child.getContainer().offset, offset: position.offset - child.container.offset,
affinity: position.affinity, affinity: position.affinity,
)); ));
return TextRange( return TextRange(
start: rangeInChild.start + child.getContainer().offset, start: rangeInChild.start + child.container.offset,
end: rangeInChild.end + child.getContainer().offset, end: rangeInChild.end + child.container.offset,
); );
} }
@ -362,7 +362,7 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
Offset getOffsetForCaret(TextPosition position) { Offset getOffsetForCaret(TextPosition position) {
final child = childAtPosition(position); final child = childAtPosition(position);
return child.getOffsetForCaret(TextPosition( return child.getOffsetForCaret(TextPosition(
offset: position.offset - child.getContainer().offset, offset: position.offset - child.container.offset,
affinity: position.affinity, affinity: position.affinity,
)) + )) +
(child.parentData as BoxParentData).offset; (child.parentData as BoxParentData).offset;
@ -375,7 +375,7 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
final localPosition = final localPosition =
child.getPositionForOffset(offset - parentData.offset); child.getPositionForOffset(offset - parentData.offset);
return TextPosition( return TextPosition(
offset: localPosition.offset + child.getContainer().offset, offset: localPosition.offset + child.container.offset,
affinity: localPosition.affinity, affinity: localPosition.affinity,
); );
} }
@ -383,7 +383,7 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
@override @override
TextRange getWordBoundary(TextPosition position) { TextRange getWordBoundary(TextPosition position) {
final child = childAtPosition(position); final child = childAtPosition(position);
final nodeOffset = child.getContainer().offset; final nodeOffset = child.container.offset;
final childWord = child final childWord = child
.getWordBoundary(TextPosition(offset: position.offset - nodeOffset)); .getWordBoundary(TextPosition(offset: position.offset - nodeOffset));
return TextRange( return TextRange(
@ -394,14 +394,14 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
@override @override
TextPosition? getPositionAbove(TextPosition position) { TextPosition? getPositionAbove(TextPosition position) {
assert(position.offset < getContainer().length); assert(position.offset < container.length);
final child = childAtPosition(position); final child = childAtPosition(position);
final childLocalPosition = final childLocalPosition =
TextPosition(offset: position.offset - child.getContainer().offset); TextPosition(offset: position.offset - child.container.offset);
final result = child.getPositionAbove(childLocalPosition); final result = child.getPositionAbove(childLocalPosition);
if (result != null) { if (result != null) {
return TextPosition(offset: result.offset + child.getContainer().offset); return TextPosition(offset: result.offset + child.container.offset);
} }
final sibling = childBefore(child); final sibling = childBefore(child);
@ -410,25 +410,24 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
} }
final caretOffset = child.getOffsetForCaret(childLocalPosition); final caretOffset = child.getOffsetForCaret(childLocalPosition);
final testPosition = final testPosition = TextPosition(offset: sibling.container.length - 1);
TextPosition(offset: sibling.getContainer().length - 1);
final testOffset = sibling.getOffsetForCaret(testPosition); final testOffset = sibling.getOffsetForCaret(testPosition);
final finalOffset = Offset(caretOffset.dx, testOffset.dy); final finalOffset = Offset(caretOffset.dx, testOffset.dy);
return TextPosition( return TextPosition(
offset: sibling.getContainer().offset + offset: sibling.container.offset +
sibling.getPositionForOffset(finalOffset).offset); sibling.getPositionForOffset(finalOffset).offset);
} }
@override @override
TextPosition? getPositionBelow(TextPosition position) { TextPosition? getPositionBelow(TextPosition position) {
assert(position.offset < getContainer().length); assert(position.offset < container.length);
final child = childAtPosition(position); final child = childAtPosition(position);
final childLocalPosition = final childLocalPosition =
TextPosition(offset: position.offset - child.getContainer().offset); TextPosition(offset: position.offset - child.container.offset);
final result = child.getPositionBelow(childLocalPosition); final result = child.getPositionBelow(childLocalPosition);
if (result != null) { if (result != null) {
return TextPosition(offset: result.offset + child.getContainer().offset); return TextPosition(offset: result.offset + child.container.offset);
} }
final sibling = childAfter(child); final sibling = childAfter(child);
@ -440,7 +439,7 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
final testOffset = sibling.getOffsetForCaret(const TextPosition(offset: 0)); final testOffset = sibling.getOffsetForCaret(const TextPosition(offset: 0));
final finalOffset = Offset(caretOffset.dx, testOffset.dy); final finalOffset = Offset(caretOffset.dx, testOffset.dy);
return TextPosition( return TextPosition(
offset: sibling.getContainer().offset + offset: sibling.container.offset +
sibling.getPositionForOffset(finalOffset).offset); sibling.getPositionForOffset(finalOffset).offset);
} }
@ -448,7 +447,7 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
double preferredLineHeight(TextPosition position) { double preferredLineHeight(TextPosition position) {
final child = childAtPosition(position); final child = childAtPosition(position);
return child.preferredLineHeight( return child.preferredLineHeight(
TextPosition(offset: position.offset - child.getContainer().offset)); TextPosition(offset: position.offset - child.container.offset));
} }
@override @override
@ -460,10 +459,10 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
null); null);
} }
final baseNode = getContainer().queryChild(selection.start, false).node; final baseNode = container.queryChild(selection.start, false).node;
var baseChild = firstChild; var baseChild = firstChild;
while (baseChild != null) { while (baseChild != null) {
if (baseChild.getContainer() == baseNode) { if (baseChild.container == baseNode) {
break; break;
} }
baseChild = childAfter(baseChild); baseChild = childAfter(baseChild);
@ -471,7 +470,7 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
assert(baseChild != null); assert(baseChild != null);
final basePoint = baseChild!.getBaseEndpointForSelection( final basePoint = baseChild!.getBaseEndpointForSelection(
localSelection(baseChild.getContainer(), selection, true)); localSelection(baseChild.container, selection, true));
return TextSelectionPoint( return TextSelectionPoint(
basePoint.point + (baseChild.parentData as BoxParentData).offset, basePoint.point + (baseChild.parentData as BoxParentData).offset,
basePoint.direction); basePoint.direction);
@ -486,11 +485,11 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
null); null);
} }
final extentNode = getContainer().queryChild(selection.end, false).node; final extentNode = container.queryChild(selection.end, false).node;
var extentChild = firstChild; var extentChild = firstChild;
while (extentChild != null) { while (extentChild != null) {
if (extentChild.getContainer() == extentNode) { if (extentChild.container == extentNode) {
break; break;
} }
extentChild = childAfter(extentChild); extentChild = childAfter(extentChild);
@ -498,7 +497,7 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
assert(extentChild != null); assert(extentChild != null);
final extentPoint = extentChild!.getExtentEndpointForSelection( final extentPoint = extentChild!.getExtentEndpointForSelection(
localSelection(extentChild.getContainer(), selection, true)); localSelection(extentChild.container, selection, true));
return TextSelectionPoint( return TextSelectionPoint(
extentPoint.point + (extentChild.parentData as BoxParentData).offset, extentPoint.point + (extentChild.parentData as BoxParentData).offset,
extentPoint.direction); extentPoint.direction);
@ -548,7 +547,7 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
Rect getLocalRectForCaret(TextPosition position) { Rect getLocalRectForCaret(TextPosition position) {
final child = childAtPosition(position); final child = childAtPosition(position);
final localPosition = TextPosition( final localPosition = TextPosition(
offset: position.offset - child.getContainer().offset, offset: position.offset - child.container.offset,
affinity: position.affinity, affinity: position.affinity,
); );
final parentData = child.parentData as BoxParentData; final parentData = child.parentData as BoxParentData;
@ -557,10 +556,10 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
@override @override
TextPosition globalToLocalPosition(TextPosition position) { TextPosition globalToLocalPosition(TextPosition position) {
assert(getContainer().containsOffset(position.offset), assert(container.containsOffset(position.offset),
'The provided text position is not in the current node'); 'The provided text position is not in the current node');
return TextPosition( return TextPosition(
offset: position.offset - getContainer().documentOffset, offset: position.offset - container.documentOffset,
affinity: position.affinity, affinity: position.affinity,
); );
} }
@ -569,7 +568,7 @@ class RenderEditableTextBlock extends RenderEditableContainerBox
Rect getCaretPrototype(TextPosition position) { Rect getCaretPrototype(TextPosition position) {
final child = childAtPosition(position); final child = childAtPosition(position);
final localPosition = TextPosition( final localPosition = TextPosition(
offset: position.offset - child.getContainer().offset, offset: position.offset - child.container.offset,
affinity: position.affinity, affinity: position.affinity,
); );
return child.getCaretPrototype(localPosition); return child.getCaretPrototype(localPosition);

@ -10,7 +10,7 @@ import 'package:tuple/tuple.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import '../../flutter_quill.dart'; import '../../flutter_quill.dart';
import '../models/documents/nodes/container.dart' as container; import '../models/documents/nodes/container.dart' as container_node;
import '../models/documents/nodes/leaf.dart' as leaf; import '../models/documents/nodes/leaf.dart' as leaf;
import '../models/documents/nodes/line.dart'; import '../models/documents/nodes/line.dart';
import '../models/documents/nodes/node.dart'; import '../models/documents/nodes/node.dart';
@ -839,9 +839,7 @@ class RenderEditableTextLine extends RenderEditableBox {
} }
@override @override
container.Container getContainer() { container_node.Container get container => line;
return line;
}
double get cursorWidth => cursorCont.style.width; double get cursorWidth => cursorCont.style.width;
@ -1188,10 +1186,10 @@ class RenderEditableTextLine extends RenderEditableBox {
@override @override
TextPosition globalToLocalPosition(TextPosition position) { TextPosition globalToLocalPosition(TextPosition position) {
assert(getContainer().containsOffset(position.offset), assert(container.containsOffset(position.offset),
'The provided text position is not in the current node'); 'The provided text position is not in the current node');
return TextPosition( return TextPosition(
offset: position.offset - getContainer().documentOffset, offset: position.offset - container.documentOffset,
affinity: position.affinity, affinity: position.affinity,
); );
} }

Loading…
Cancel
Save