Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ void main() {
await tester.tap(find.byType(RawEditor));
controller.updateSelection(const TextSelection.collapsed(offset: 0));
await tester.pump();
await tester.ime.typeText(iputText, finder: find.byType(RawEditor));
await tester.ime.typeText(iputText);
await tester.pump();
controller.updateSelection(
TextSelection.collapsed(offset: document.length - 1));
await tester.pump();
await tester.ime.typeText(iputText, finder: find.byType(RawEditor));
await tester.ime.typeText(iputText);
},
reportKey: 'timeline',
);
Expand Down
21 changes: 20 additions & 1 deletion packages/fleather/lib/src/rendering/editable_text_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,26 @@ class RenderEditableTextBlock extends RenderEditableContainerBox

@override
List<TextBox> getBoxesForSelection(TextSelection selection) {
throw UnimplementedError();
final boxes = <TextBox>[];
var child = firstChild;
while (child != null) {
if (intersectsWithSelection(child.node, selection, fromParent: true)) {
final childSelection =
localSelection(child.node, selection, fromParent: true);
final childOffset = (child.parentData as BoxParentData).offset;
boxes.addAll(child.getBoxesForSelection(childSelection).map((box) {
return TextBox.fromLTRBD(
box.left + childOffset.dx,
box.top + childOffset.dy,
box.right + childOffset.dx,
box.bottom + childOffset.dy,
box.direction,
);
}));
}
child = childAfter(child);
}
return boxes;
}

@override
Expand Down
31 changes: 29 additions & 2 deletions packages/fleather/lib/src/rendering/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@ class RenderEditor extends RenderEditableContainerBox
return defaultHitTestChildren(result, position: effectivePosition);
}

@override
bool hitTestSelf(Offset position) => true;

void _paintHandleLayers(
PaintingContext context, List<TextSelectionPoint> endpoints) {
var startPoint = endpoints[0].point + paintOffset;
Expand Down Expand Up @@ -757,8 +760,32 @@ class RenderEditor extends RenderEditableContainerBox
final childLocalRect = targetChild.getLocalRectForCaret(localPosition);

final boxParentData = targetChild.parentData as BoxParentData;
return childLocalRect.shift(Offset(
resolvedPadding!.left, boxParentData.offset.dy + paintOffset.dy));
return childLocalRect.shift(boxParentData.offset + paintOffset);
}

/// Returns text boxes for a document selection in this editor's coordinates.
List<TextBox> getBoxesForSelection(TextSelection selection) {
final boxes = <TextBox>[];
var child = firstChild;
while (child != null) {
if (intersectsWithSelection(child.node, selection, fromParent: true)) {
final childSelection =
localSelection(child.node, selection, fromParent: true);
final childOffset =
(child.parentData as BoxParentData).offset + paintOffset;
boxes.addAll(child.getBoxesForSelection(childSelection).map((box) {
return TextBox.fromLTRBD(
box.left + childOffset.dx,
box.top + childOffset.dy,
box.right + childOffset.dx,
box.bottom + childOffset.dy,
box.direction,
);
}));
}
child = childAfter(child);
}
return boxes;
}

// Start floating cursor
Expand Down
3 changes: 3 additions & 0 deletions packages/fleather/lib/src/widgets/editable_text_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class EditableTextBlock extends StatelessWidget {
final LinkActionPicker linkActionPicker;
final ValueChanged<String?>? onLaunchUrl;
final EdgeInsets? contentPadding;
final FleatherScribblePlaceholder? scribblePlaceholder;

const EditableTextBlock({
super.key,
Expand All @@ -45,6 +46,7 @@ class EditableTextBlock extends StatelessWidget {
required this.linkActionPicker,
this.onLaunchUrl,
this.contentPadding,
this.scribblePlaceholder,
});

@override
Expand Down Expand Up @@ -87,6 +89,7 @@ class EditableTextBlock extends StatelessWidget {
linkActionPicker: linkActionPicker,
onLaunchUrl: onLaunchUrl,
textWidthBasis: textWidthBasis,
scribblePlaceholder: scribblePlaceholder,
),
cursorController: cursorController,
selection: selection,
Expand Down
Loading
Loading