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/widgets.dart';
@ -291,8 +293,8 @@ class RenderParagraphProxy extends RenderProxyBox
child!.getWordBoundary(position);
@override
List<TextBox> getBoxesForSelection(TextSelection selection) =>
child!.getBoxesForSelection(selection);
List<TextBox> getBoxesForSelection(TextSelection selection) => child!
.getBoxesForSelection(selection, boxHeightStyle: BoxHeightStyle.strut);
@override
void performLayout() {

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

Loading…
Cancel
Save