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.
pull/531/head
X Code 3 years ago
parent d1fa59a759
commit e9b119299a
  1. 6
      lib/src/widgets/proxy.dart
  2. 10
      lib/src/widgets/text_line.dart

@ -1,3 +1,5 @@
import 'dart:ui';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
@ -291,8 +293,8 @@ class RenderParagraphProxy extends RenderProxyBox
child!.getWordBoundary(position); child!.getWordBoundary(position);
@override @override
List<TextBox> getBoxesForSelection(TextSelection selection) => List<TextBox> getBoxesForSelection(TextSelection selection) => child!
child!.getBoxesForSelection(selection); .getBoxesForSelection(selection, boxHeightStyle: BoxHeightStyle.strut);
@override @override
void performLayout() { void performLayout() {

@ -441,9 +441,10 @@ class RenderEditableTextLine extends RenderEditableBox {
} }
final containsSelection = containsTextSelection(); final containsSelection = containsTextSelection();
if (attached && containsCursor()) { if (_attachedToCursorController) {
cursorCont.removeListener(markNeedsLayout); cursorCont.removeListener(markNeedsLayout);
cursorCont.color.removeListener(safeMarkNeedsPaint); cursorCont.color.removeListener(safeMarkNeedsPaint);
_attachedToCursorController = false;
} }
textSelection = t; textSelection = t;
@ -452,6 +453,7 @@ class RenderEditableTextLine extends RenderEditableBox {
if (attached && containsCursor()) { if (attached && containsCursor()) {
cursorCont.addListener(markNeedsLayout); cursorCont.addListener(markNeedsLayout);
cursorCont.color.addListener(safeMarkNeedsPaint); cursorCont.color.addListener(safeMarkNeedsPaint);
_attachedToCursorController = true;
} }
if (containsSelection || containsTextSelection()) { if (containsSelection || containsTextSelection()) {
@ -680,6 +682,8 @@ class RenderEditableTextLine extends RenderEditableBox {
// Start render box overrides // Start render box overrides
bool _attachedToCursorController = false;
@override @override
void attach(covariant PipelineOwner owner) { void attach(covariant PipelineOwner owner) {
super.attach(owner); super.attach(owner);
@ -690,6 +694,7 @@ class RenderEditableTextLine extends RenderEditableBox {
if (containsCursor()) { if (containsCursor()) {
cursorCont.addListener(markNeedsLayout); cursorCont.addListener(markNeedsLayout);
cursorCont.color.addListener(safeMarkNeedsPaint); cursorCont.color.addListener(safeMarkNeedsPaint);
_attachedToCursorController = true;
} }
} }
@ -701,9 +706,10 @@ class RenderEditableTextLine extends RenderEditableBox {
} }
cursorCont.floatingCursorTextPosition cursorCont.floatingCursorTextPosition
.removeListener(_onFloatingCursorChange); .removeListener(_onFloatingCursorChange);
if (containsCursor()) { if (_attachedToCursorController) {
cursorCont.removeListener(markNeedsLayout); cursorCont.removeListener(markNeedsLayout);
cursorCont.color.removeListener(safeMarkNeedsPaint); cursorCont.color.removeListener(safeMarkNeedsPaint);
_attachedToCursorController = false;
} }
} }

Loading…
Cancel
Save