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
7809651c
Unverified
Commit
7809651c
authored
May 09, 2018
by
Michael Goderbauer
Committed by
GitHub
May 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Put cursor at end of field if textfield is focused (#17367)
parent
501316fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+3
-0
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+25
-0
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
7809651c
...
...
@@ -620,6 +620,9 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
if
(!
_hasFocus
)
{
// Clear the selection and composition state if this widget lost focus.
_value
=
new
TextEditingValue
(
text:
_value
.
text
);
}
else
if
(!
_value
.
selection
.
isValid
)
{
// Place cursor at the end if the selection is invalid when we receive focus.
widget
.
controller
.
selection
=
new
TextSelection
.
collapsed
(
offset:
_value
.
text
.
length
);
}
updateKeepAlive
();
}
...
...
packages/flutter/test/widgets/editable_text_test.dart
View file @
7809651c
...
...
@@ -783,6 +783,31 @@ void main() {
expect
(
render
.
text
.
style
.
fontStyle
,
FontStyle
.
italic
);
});
testWidgets
(
'autofocus sets cursor to the end of text'
,
(
WidgetTester
tester
)
async
{
const
String
text
=
'hello world'
;
final
FocusScopeNode
focusScopeNode
=
new
FocusScopeNode
();
final
FocusNode
focusNode
=
new
FocusNode
();
controller
.
text
=
text
;
await
tester
.
pumpWidget
(
new
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
new
FocusScope
(
node:
focusScopeNode
,
autofocus:
true
,
child:
new
EditableText
(
controller:
controller
,
focusNode:
focusNode
,
autofocus:
true
,
style:
textStyle
,
cursorColor:
cursorColor
,
),
),
));
expect
(
focusNode
.
hasFocus
,
true
);
expect
(
controller
.
selection
.
isCollapsed
,
true
);
expect
(
controller
.
selection
.
baseOffset
,
text
.
length
);
});
}
class
MockTextSelectionControls
extends
Mock
implements
TextSelectionControls
{}
...
...
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