Skip to content

Commit

Permalink
Cursor is tiny when there's no text in an input
Browse files Browse the repository at this point in the history
Now we use a zero-width space to force the engine to resolve the font and tell
us how large the text is likely to be once there's text in the widget.

Fixes flutter#302
  • Loading branch information
abarth committed Nov 13, 2015
1 parent 71578c8 commit 69e511d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 3 additions & 4 deletions packages/flutter/lib/src/rendering/editable_paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ class RenderEditableParagraph extends RenderParagraph {
_scrollOffset = scrollOffset,
super(text);

Color _cursorColor;
bool _showCursor;
SizeChangedCallback onContentSizeChanged;
Offset _scrollOffset;

Size _contentSize;

Color get cursorColor => _cursorColor;
Color _cursorColor;
void set cursorColor(Color value) {
if (_cursorColor == value)
return;
Expand All @@ -45,6 +42,7 @@ class RenderEditableParagraph extends RenderParagraph {
}

bool get showCursor => _showCursor;
bool _showCursor;
void set showCursor(bool value) {
if (_showCursor == value)
return;
Expand All @@ -53,6 +51,7 @@ class RenderEditableParagraph extends RenderParagraph {
}

Offset get scrollOffset => _scrollOffset;
Offset _scrollOffset;
void set scrollOffset(Offset value) {
if (_scrollOffset == value)
return;
Expand Down
5 changes: 4 additions & 1 deletion packages/flutter/lib/src/widgets/editable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ class EditableTextState extends State<EditableText> {
}
}

final String _kZeroWidthSpace = new String.fromCharCode(0x200B);

class _EditableTextWidget extends LeafRenderObjectWidget {
_EditableTextWidget({
Key key,
Expand Down Expand Up @@ -275,8 +277,9 @@ class _EditableTextWidget extends LeafRenderObjectWidget {
]);
}

String text = value.text;
return new StyledTextSpan(style, <TextSpan>[
new PlainTextSpan(value.text)
new PlainTextSpan(text.isEmpty ? _kZeroWidthSpace : text)
]);
}
}

0 comments on commit 69e511d

Please sign in to comment.