Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
963fb413
Commit
963fb413
authored
Sep 22, 2015
by
Jason Simmons
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1245 from jason-simmons/editable_text_initial_blink
Ensure that EditableText always shows a cursor
parents
9b84e6b8
58b421aa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
16 deletions
+63
-16
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+22
-13
input_test.dart
packages/unit/test/widget/input_test.dart
+41
-3
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
963fb413
...
...
@@ -156,6 +156,13 @@ class EditableText extends StatefulComponent {
Timer
_cursorTimer
;
bool
_showCursor
=
false
;
/// Whether the blinking cursor is visible (exposed for testing).
bool
get
test_showCursor
=>
_showCursor
;
/// The cursor blink interval (exposed for testing).
Duration
get
test_cursorBlinkPeriod
=>
new
Duration
(
milliseconds:
_kCursorBlinkPeriod
);
void
_cursorTick
(
Timer
timer
)
{
setState
(()
{
_showCursor
=
!
_showCursor
;
...
...
@@ -184,11 +191,12 @@ class EditableText extends StatefulComponent {
if
(!
_showCursor
)
return
;
double
cursorHeight
=
style
.
fontSize
+
2.0
*
_kCursorHeightOffset
;
Rect
cursorRect
=
new
Rect
.
fromLTWH
(
_kCursorGap
,
-
_kCursorHeightOffset
,
(
size
.
height
-
cursorHeight
)
/
2.0
,
_kCursorWidth
,
style
.
fontSize
+
2
*
_kCursorHeightOffse
t
cursorHeigh
t
);
canvas
.
drawRect
(
cursorRect
,
new
Paint
()..
color
=
cursorColor
);
}
...
...
@@ -203,21 +211,22 @@ class EditableText extends StatefulComponent {
else
if
(!
focused
&&
_cursorTimer
!=
null
)
_stopCursorTimer
();
if
(!
value
.
composing
.
isValid
)
{
Widget
text
;
if
(
value
.
composing
.
isValid
)
{
TextStyle
composingStyle
=
style
.
merge
(
const
TextStyle
(
decoration:
underline
));
text
=
new
StyledText
(
elements:
[
style
,
value
.
textBefore
(
value
.
composing
),
[
composingStyle
,
value
.
textInside
(
value
.
composing
)],
value
.
textAfter
(
value
.
composing
)
]);
}
else
{
// TODO(eseidel): This is the wrong height if empty!
return
new
Row
([
new
Text
(
value
.
text
,
style:
style
)]
);
text
=
new
Text
(
value
.
text
,
style:
style
);
}
TextStyle
composingStyle
=
style
.
merge
(
const
TextStyle
(
decoration:
underline
));
StyledText
text
=
new
StyledText
(
elements:
[
style
,
value
.
textBefore
(
value
.
composing
),
[
composingStyle
,
value
.
textInside
(
value
.
composing
)],
value
.
textAfter
(
value
.
composing
)
]);
Widget
cursor
=
new
Container
(
height:
style
.
fontSize
,
height:
style
.
fontSize
*
style
.
height
,
width:
_kCursorGap
+
_kCursorWidth
,
child:
new
CustomPaint
(
callback:
_paintCursor
,
token:
_showCursor
)
);
...
...
packages/unit/test/widget/input_test.dart
View file @
963fb413
import
'package:mojo_services/keyboard/keyboard.mojom.dart'
;
import
'package:quiver/testing/async.dart'
;
import
'package:sky/rendering.dart'
;
import
'package:sky/services.dart'
;
import
'package:sky/widgets.dart'
;
...
...
@@ -20,12 +21,12 @@ class MockKeyboard implements KeyboardService {
}
void
main
(
)
{
MockKeyboard
mockKeyboard
=
new
MockKeyboard
();
serviceMocker
.
registerMockService
(
KeyboardServiceName
,
mockKeyboard
);
test
(
'Editable text has consistent width'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
MockKeyboard
mockKeyboard
=
new
MockKeyboard
();
serviceMocker
.
registerMockService
(
KeyboardServiceName
,
mockKeyboard
);
GlobalKey
inputKey
=
new
GlobalKey
();
String
inputValue
;
...
...
@@ -57,4 +58,41 @@ void main() {
// Check that the Input with text has the same size as the empty Input.
expect
((
input
.
renderObject
as
RenderBox
).
size
,
equals
(
emptyInputSize
));
});
test
(
'Cursor blinks'
,
()
{
WidgetTester
tester
=
new
WidgetTester
();
GlobalKey
inputKey
=
new
GlobalKey
();
Widget
builder
()
{
return
new
Center
(
child:
new
Input
(
key:
inputKey
,
placeholder:
'Placeholder'
)
);
}
new
FakeAsync
().
run
((
async
)
{
tester
.
pumpFrame
(
builder
);
EditableText
editableText
=
tester
.
findWidget
(
(
Widget
widget
)
=>
widget
is
EditableText
);
// Check that the cursor visibility toggles after each blink interval.
void
checkCursorToggle
()
{
bool
initialShowCursor
=
editableText
.
test_showCursor
;
async
.
elapse
(
editableText
.
test_cursorBlinkPeriod
);
expect
(
editableText
.
test_showCursor
,
equals
(!
initialShowCursor
));
async
.
elapse
(
editableText
.
test_cursorBlinkPeriod
);
expect
(
editableText
.
test_showCursor
,
equals
(
initialShowCursor
));
}
checkCursorToggle
();
// Try the test again with a nonempty EditableText.
mockKeyboard
.
client
.
setComposingText
(
'X'
,
1
);
checkCursorToggle
();
});
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment