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
eb668c3f
Commit
eb668c3f
authored
Jun 30, 2017
by
Jason Simmons
Committed by
GitHub
Jun 30, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Keep text selection ranges within the length of the text (#11055)
Fixes
https://github.com/flutter/flutter/issues/11041
parent
2c4ec1c9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
1 deletion
+23
-1
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+5
-1
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+18
-0
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
eb668c3f
...
...
@@ -69,7 +69,9 @@ class TextEditingController extends ValueNotifier<TextEditingValue> {
/// this value should only be set between frames, e.g. in response to user
/// actions, not during the build, layout, or paint phases.
set
text
(
String
newText
)
{
value
=
value
.
copyWith
(
text:
newText
,
composing:
TextRange
.
empty
);
value
=
value
.
copyWith
(
text:
newText
,
selection:
const
TextSelection
.
collapsed
(
offset:
-
1
),
composing:
TextRange
.
empty
);
}
/// The currently selected [text].
...
...
@@ -82,6 +84,8 @@ class TextEditingController extends ValueNotifier<TextEditingValue> {
/// this value should only be set between frames, e.g. in response to user
/// actions, not during the build, layout, or paint phases.
set
selection
(
TextSelection
newSelection
)
{
if
(
newSelection
.
start
>
text
.
length
||
newSelection
.
end
>
text
.
length
)
throw
new
FlutterError
(
'invalid text selection:
$newSelection
'
);
value
=
value
.
copyWith
(
selection:
newSelection
,
composing:
TextRange
.
empty
);
}
...
...
packages/flutter/test/material/text_field_test.dart
View file @
eb668c3f
...
...
@@ -1574,4 +1574,22 @@ void main() {
expect
(
controller1
.
selection
,
equals
(
TextRange
.
empty
));
}
);
testWidgets
(
'Selection is consistent with text length'
,
(
WidgetTester
tester
)
async
{
final
TextEditingController
controller
=
new
TextEditingController
();
controller
.
text
=
'abcde'
;
controller
.
selection
=
const
TextSelection
.
collapsed
(
offset:
5
);
controller
.
text
=
''
;
expect
(
controller
.
selection
.
start
,
lessThanOrEqualTo
(
0
));
expect
(
controller
.
selection
.
end
,
lessThanOrEqualTo
(
0
));
expect
(()
{
controller
.
selection
=
const
TextSelection
.
collapsed
(
offset:
10
);
},
throwsFlutterError
);
}
);
}
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