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
2e883f85
Unverified
Commit
2e883f85
authored
Jan 07, 2019
by
Jonah Williams
Committed by
GitHub
Jan 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Skip formatters if text has not changed (#24779)
parent
3a37b9e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletion
+42
-1
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+1
-1
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+41
-0
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
2e883f85
...
...
@@ -914,7 +914,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
void
_formatAndSetValue
(
TextEditingValue
value
)
{
final
bool
textChanged
=
_value
?.
text
!=
value
?.
text
;
if
(
widget
.
inputFormatters
!=
null
&&
widget
.
inputFormatters
.
isNotEmpty
)
{
if
(
textChanged
&&
widget
.
inputFormatters
!=
null
&&
widget
.
inputFormatters
.
isNotEmpty
)
{
for
(
TextInputFormatter
formatter
in
widget
.
inputFormatters
)
value
=
formatter
.
formatEditUpdate
(
_value
,
value
);
_value
=
value
;
...
...
packages/flutter/test/widgets/editable_text_test.dart
View file @
2e883f85
...
...
@@ -1938,6 +1938,47 @@ testWidgets(
expect
(
controller
.
selection
.
baseOffset
,
11
);
});
testWidgets
(
'Formatters are skipped if text has not changed'
,
(
WidgetTester
tester
)
async
{
int
called
=
0
;
final
TextInputFormatter
formatter
=
TextInputFormatter
.
withFunction
((
TextEditingValue
oldValue
,
TextEditingValue
newValue
)
{
called
+=
1
;
return
newValue
;
});
final
TextEditingController
controller
=
TextEditingController
();
final
EditableText
editableText
=
EditableText
(
controller:
controller
,
backgroundCursorColor:
Colors
.
red
,
cursorColor:
Colors
.
red
,
focusNode:
FocusNode
(),
style:
textStyle
,
inputFormatters:
<
TextInputFormatter
>[
formatter
,
],
textDirection:
TextDirection
.
ltr
,
);
await
tester
.
pumpWidget
(
editableText
);
final
EditableTextState
state
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
state
.
updateEditingValue
(
const
TextEditingValue
(
text:
'a'
,
));
expect
(
called
,
1
);
// same value.
state
.
updateEditingValue
(
const
TextEditingValue
(
text:
'a'
,
));
expect
(
called
,
1
);
// same value with different selection.
state
.
updateEditingValue
(
const
TextEditingValue
(
text:
'a'
,
selection:
TextSelection
.
collapsed
(
offset:
1
),
));
// different value.
state
.
updateEditingValue
(
const
TextEditingValue
(
text:
'b'
,
));
expect
(
called
,
2
);
});
}
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