Skip to content

Commit e9b1192

Browse files
committed
Improves selection rects to have consistent height regardless of individual segment text styles
Fixes an issue where editable text line would stay subscribed to cursor events.
1 parent d1fa59a commit e9b1192

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/src/widgets/proxy.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:ui';
2+
13
import 'package:flutter/rendering.dart';
24
import 'package:flutter/widgets.dart';
35

@@ -291,8 +293,8 @@ class RenderParagraphProxy extends RenderProxyBox
291293
child!.getWordBoundary(position);
292294

293295
@override
294-
List<TextBox> getBoxesForSelection(TextSelection selection) =>
295-
child!.getBoxesForSelection(selection);
296+
List<TextBox> getBoxesForSelection(TextSelection selection) => child!
297+
.getBoxesForSelection(selection, boxHeightStyle: BoxHeightStyle.strut);
296298

297299
@override
298300
void performLayout() {

lib/src/widgets/text_line.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,10 @@ class RenderEditableTextLine extends RenderEditableBox {
441441
}
442442

443443
final containsSelection = containsTextSelection();
444-
if (attached && containsCursor()) {
444+
if (_attachedToCursorController) {
445445
cursorCont.removeListener(markNeedsLayout);
446446
cursorCont.color.removeListener(safeMarkNeedsPaint);
447+
_attachedToCursorController = false;
447448
}
448449

449450
textSelection = t;
@@ -452,6 +453,7 @@ class RenderEditableTextLine extends RenderEditableBox {
452453
if (attached && containsCursor()) {
453454
cursorCont.addListener(markNeedsLayout);
454455
cursorCont.color.addListener(safeMarkNeedsPaint);
456+
_attachedToCursorController = true;
455457
}
456458

457459
if (containsSelection || containsTextSelection()) {
@@ -680,6 +682,8 @@ class RenderEditableTextLine extends RenderEditableBox {
680682

681683
// Start render box overrides
682684

685+
bool _attachedToCursorController = false;
686+
683687
@override
684688
void attach(covariant PipelineOwner owner) {
685689
super.attach(owner);
@@ -690,6 +694,7 @@ class RenderEditableTextLine extends RenderEditableBox {
690694
if (containsCursor()) {
691695
cursorCont.addListener(markNeedsLayout);
692696
cursorCont.color.addListener(safeMarkNeedsPaint);
697+
_attachedToCursorController = true;
693698
}
694699
}
695700

@@ -701,9 +706,10 @@ class RenderEditableTextLine extends RenderEditableBox {
701706
}
702707
cursorCont.floatingCursorTextPosition
703708
.removeListener(_onFloatingCursorChange);
704-
if (containsCursor()) {
709+
if (_attachedToCursorController) {
705710
cursorCont.removeListener(markNeedsLayout);
706711
cursorCont.color.removeListener(safeMarkNeedsPaint);
712+
_attachedToCursorController = false;
707713
}
708714
}
709715

0 commit comments

Comments
 (0)