-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Description
Use case
I've created a rich text editor for Flutter and currently work on cleaning up and refactoring its rendering layer.
In the editor I'm taking advantage of the built-in RenderParagraph to represent a single paragraph in a document.
Since I'm using it in an editable context I need it to provide a few more metrics related to handling of editing cursor:
preferredLineHeightgetFullHeightForCaretgetLineBoundary
These methods would be proxying to the underlying TextPainter instance. Right now I have implemented a workaround for preferredLineHeight but it doesn't seem like I can create one for getFullHeightForCaret or getLineBoundary.
I noticed that RenderParagraph already exposes some editing-specific methods (getOffsetForCaret and getBoxesForSelection) so it doesn't seem like it'd go against certain design goals for this class.
Proposal
I'd like to extend RenderParagraph public interface with following three methods:
/// An estimate of the height of a line in the text. See [TextPainter.preferredLineHeight].
/// This does not required the layout to be updated.
double get preferredLineHeight => _textPainter.preferredLineHeight;
/// Returns the tight bounded height of the glyph at the given [position].
///
/// Valid only after [layout].
double? getFullHeightForCaret(TextPosition position, Rect caretPrototype) {
assert(!debugNeedsLayout);
_layoutTextWithConstraints(constraints);
return _textPainter.getFullHeightForCaret(position, caretPrototype);
}
/// Returns the text range of the line at the given offset.
///
/// The newline, if any, is included in the range.
TextRange getLineBoundary(TextPosition position) {
assert(!debugNeedsLayout);
_layoutTextWithConstraints(constraints);
return _textPainter.getLineBoundary(position);
}I will be submitting a PR with above changes shortly, just need to go over the contribution checklist.