diff --git a/CHANGELOG.md b/CHANGELOG.md index 382d4f01..1d451d3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [2.0.3] +* Fix cursor when line contains image. + ## [2.0.2] * Address KeyboardListener class name conflict. diff --git a/lib/src/widgets/cursor.dart b/lib/src/widgets/cursor.dart index d315f785..dd449c7c 100644 --- a/lib/src/widgets/cursor.dart +++ b/lib/src/widgets/cursor.dart @@ -245,24 +245,21 @@ class CursorPainter { /// Paints cursor on [canvas] at specified [position]. /// [offset] is global top left (x, y) of text line /// [position] is relative (x) in text line - void paint(Canvas canvas, Offset offset, TextPosition position, bool lineHasEmbed) { - var caretOffset = - editable!.getOffsetForCaret(position, prototype) + offset; - if (lineHasEmbed) { - // relative (x, y) to global offset - var relativeCaretOffset = editable!.getOffsetForCaret(position, prototype); - if (relativeCaretOffset == Offset.zero) { - relativeCaretOffset = editable!.getOffsetForCaret( - TextPosition( - offset: position.offset - 1, affinity: position.affinity), - prototype); - // Hardcoded 6 as estimate of the width of a character - relativeCaretOffset = - Offset(relativeCaretOffset.dx + 6, relativeCaretOffset.dy); - } - caretOffset = relativeCaretOffset + offset; + void paint( + Canvas canvas, Offset offset, TextPosition position, bool lineHasEmbed) { + // relative (x, y) to global offset + var relativeCaretOffset = editable!.getOffsetForCaret(position, prototype); + if (lineHasEmbed && relativeCaretOffset == Offset.zero) { + relativeCaretOffset = editable!.getOffsetForCaret( + TextPosition( + offset: position.offset - 1, affinity: position.affinity), + prototype); + // Hardcoded 6 as estimate of the width of a character + relativeCaretOffset = + Offset(relativeCaretOffset.dx + 6, relativeCaretOffset.dy); } + final caretOffset = relativeCaretOffset + offset; var caretRect = prototype.shift(caretOffset); if (style.offset != null) { caretRect = caretRect.shift(style.offset!); diff --git a/lib/src/widgets/text_line.dart b/lib/src/widgets/text_line.dart index e4f69a5e..f8a3f396 100644 --- a/lib/src/widgets/text_line.dart +++ b/lib/src/widgets/text_line.dart @@ -847,12 +847,14 @@ class RenderEditableTextLine extends RenderEditableBox { } } - void _paintCursor(PaintingContext context, Offset effectiveOffset, bool lineHasEmbed) { + void _paintCursor( + PaintingContext context, Offset effectiveOffset, bool lineHasEmbed) { final position = TextPosition( offset: textSelection.extentOffset - line.documentOffset, affinity: textSelection.base.affinity, ); - _cursorPainter.paint(context.canvas, effectiveOffset, position, lineHasEmbed); + _cursorPainter.paint( + context.canvas, effectiveOffset, position, lineHasEmbed); } @override diff --git a/pubspec.yaml b/pubspec.yaml index aa9753b6..5139c684 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill description: A rich text editor supporting mobile and web (Demo App @ bulletjournal.us) -version: 2.0.2 +version: 2.0.3 #author: bulletjournal homepage: https://bulletjournal.us/home/index.html repository: https://github.com/singerdmx/flutter-quill