Skip to content

Implementation of EditableTextState._scheduleShowCaretOnScreen #104500

@Oleksa5

Description

@Oleksa5

Currently it's not possible to select more text than it's visible in a scrollable. Because the function is always trying to show a padded caret rect, which for selected text happens to be at the beginning of the selection. This is because _FloatingCursorPainter.paint skips painting for non-collapsed selection and updating the cashed caret rect is performed at the end of the painting via callback to RenderEditable.

Visually there is no caret on non-collapsed selection, then what to show? Why should the beginning of the selection be treated as the caret position and not the end? Maybe the function should have another name and EditableTextState._currentCaretRect be updated to null . Or _currentCaretRect should be updated even for non-collapsed selection and placed at the extent of the selection.

Probably the simplest solution would be to add

final Rect rectToReveal;
final TextSelection selection = textEditingValue.selection;
if (selection.isCollapsed) {
  rectToReveal = targetOffset.rect;
} else {
  final List<Rect> selectionBoxes = renderEditable.getBoxesForSelection(selection);
  rectToReveal = selection.baseOffset < selection.extentOffset ?
    selectionBoxes.last : selectionBoxes.first;
}

and change

rect: caretPadding.inflateRect(targetOffset.rect)

to

rect: caretPadding.inflateRect(rectToReveal)

Also note there is another issue with scrolling while selecting text by dragging the mouse, but that has to do with the implementation of TextSelectionGestureDetectorBuilder.onDragSelectionUpdate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsc: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions