Skip to content

Commit 7f5a5a0

Browse files
authored
fix: add default selection area for empty character (#1043)
1 parent fa186a4 commit 7f5a5a0

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

lib/src/editor/block_component/rich_text/appflowy_rich_text.dart

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class _AppFlowyRichTextState extends State<AppFlowyRichText>
108108
AppFlowyAutoCompleteTextProvider? get autoCompleteTextProvider =>
109109
widget.autoCompleteTextProvider ??
110110
widget.editorState.autoCompleteTextProvider;
111+
111112
bool get enableAutoComplete =>
112113
widget.editorState.enableAutoComplete && autoCompleteTextProvider != null;
113114

@@ -293,12 +294,28 @@ class _AppFlowyRichTextState extends State<AppFlowyRichText>
293294
)
294295
.map((box) => box.toRect())
295296
.toList(growable: false);
296-
297297
if (rects == null || rects.isEmpty) {
298-
// If the rich text widget does not contain any text,
299-
// there will be no selection boxes,
300-
// so we need to return to the default selection.
301-
return [Rect.fromLTWH(0, 0, 0, paragraph?.size.height ?? 0)];
298+
/// If the rich text widget does not contain any text,
299+
/// there will be no selection boxes,
300+
/// so we need to return to the default selection.
301+
Offset position = Offset.zero;
302+
double height = paragraph?.size.height ?? 0.0;
303+
double width = 0;
304+
if (!selection.isCollapsed) {
305+
/// while selecting for an empty character, return a selection area
306+
/// with width of 2
307+
final textPosition = TextPosition(offset: textSelection.baseOffset);
308+
position = paragraph?.getOffsetForCaret(
309+
textPosition,
310+
Rect.zero,
311+
) ??
312+
position;
313+
height = paragraph?.getFullHeightForCaret(textPosition) ?? height;
314+
width = 2;
315+
}
316+
return [
317+
Rect.fromLTWH(position.dx, position.dy, width, height),
318+
];
302319
}
303320
return rects;
304321
}

0 commit comments

Comments
 (0)