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
e078c93b
Unverified
Commit
e078c93b
authored
Mar 10, 2023
by
Callum Moffat
Committed by
GitHub
Mar 10, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SelectionChangedCause for iOS keyboard-select (#122144)
SelectionChangedCause for iOS keyboard-select
parent
d7e85174
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
5 deletions
+42
-5
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+9
-1
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+18
-4
test_text_input.dart
packages/flutter_test/lib/src/test_text_input.dart
+15
-0
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
e078c93b
...
@@ -2775,7 +2775,15 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -2775,7 +2775,15 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
if
(
value
.
text
==
_value
.
text
&&
value
.
composing
==
_value
.
composing
)
{
if
(
value
.
text
==
_value
.
text
&&
value
.
composing
==
_value
.
composing
)
{
// `selection` is the only change.
// `selection` is the only change.
_handleSelectionChanged
(
value
.
selection
,
(
_textInputConnection
?.
scribbleInProgress
??
false
)
?
SelectionChangedCause
.
scribble
:
SelectionChangedCause
.
keyboard
);
SelectionChangedCause
cause
;
if
(
_textInputConnection
?.
scribbleInProgress
??
false
)
{
cause
=
SelectionChangedCause
.
scribble
;
}
else
if
(
_pointOffsetOrigin
!=
null
)
{
cause
=
SelectionChangedCause
.
forcePress
;
}
else
{
cause
=
SelectionChangedCause
.
keyboard
;
}
_handleSelectionChanged
(
value
.
selection
,
cause
);
}
else
{
}
else
{
if
(
value
.
text
!=
_value
.
text
)
{
if
(
value
.
text
!=
_value
.
text
)
{
// Hide the toolbar if the text was changed, but only hide the toolbar
// Hide the toolbar if the text was changed, but only hide the toolbar
...
...
packages/flutter/test/widgets/editable_text_test.dart
View file @
e078c93b
...
@@ -2751,6 +2751,8 @@ void main() {
...
@@ -2751,6 +2751,8 @@ void main() {
await
tester
.
pumpAndSettle
();
await
tester
.
pumpAndSettle
();
expect
(
selectionCause
,
SelectionChangedCause
.
scribble
);
expect
(
selectionCause
,
SelectionChangedCause
.
scribble
);
await
tester
.
testTextInput
.
finishScribbleInteraction
();
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
}));
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
}));
testWidgets
(
'Requests focus and changes the selection when onScribbleFocus is called'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'Requests focus and changes the selection when onScribbleFocus is called'
,
(
WidgetTester
tester
)
async
{
...
@@ -12411,6 +12413,7 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
...
@@ -12411,6 +12413,7 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
EditableText
.
debugDeterministicCursor
=
true
;
EditableText
.
debugDeterministicCursor
=
true
;
final
FocusNode
focusNode
=
FocusNode
();
final
FocusNode
focusNode
=
FocusNode
();
final
GlobalKey
key
=
GlobalKey
();
final
GlobalKey
key
=
GlobalKey
();
SelectionChangedCause
?
lastSelectionChangedCause
;
final
TextEditingController
controller
=
TextEditingController
(
text:
'ABCDEFGHIJKLMNOPQRSTUVWXYZ
\n
1234567890'
);
final
TextEditingController
controller
=
TextEditingController
(
text:
'ABCDEFGHIJKLMNOPQRSTUVWXYZ
\n
1234567890'
);
controller
.
selection
=
const
TextSelection
.
collapsed
(
offset:
0
);
controller
.
selection
=
const
TextSelection
.
collapsed
(
offset:
0
);
...
@@ -12425,6 +12428,9 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
...
@@ -12425,6 +12428,9 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
cursorColor:
Colors
.
blue
,
cursorColor:
Colors
.
blue
,
backgroundCursorColor:
Colors
.
grey
,
backgroundCursorColor:
Colors
.
grey
,
cursorOpacityAnimates:
true
,
cursorOpacityAnimates:
true
,
onSelectionChanged:
(
TextSelection
selection
,
SelectionChangedCause
?
cause
)
{
lastSelectionChangedCause
=
cause
;
},
maxLines:
2
,
maxLines:
2
,
),
),
),
),
...
@@ -12461,6 +12467,8 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
...
@@ -12461,6 +12467,8 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
// Selection should be updated based on the floating cursor location.
// Selection should be updated based on the floating cursor location.
expect
(
controller
.
selection
.
isCollapsed
,
true
);
expect
(
controller
.
selection
.
isCollapsed
,
true
);
expect
(
controller
.
selection
.
baseOffset
,
4
);
expect
(
controller
.
selection
.
baseOffset
,
4
);
expect
(
lastSelectionChangedCause
,
SelectionChangedCause
.
forcePress
);
lastSelectionChangedCause
=
null
;
state
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
,
offset:
Offset
.
zero
));
state
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
,
offset:
Offset
.
zero
));
await
tester
.
pump
();
await
tester
.
pump
();
...
@@ -12486,7 +12494,7 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
...
@@ -12486,7 +12494,7 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
));
));
// Simulate UIKit setting the selection using keyboard selection.
// Simulate UIKit setting the selection using keyboard selection.
controller
.
selection
=
const
TextSelection
(
baseOffset:
0
,
extentOffset:
4
);
state
.
updateEditingValue
(
state
.
currentTextEditingValue
.
copyWith
(
selection:
const
TextSelection
(
baseOffset:
0
,
extentOffset:
4
))
);
await
tester
.
pump
();
await
tester
.
pump
();
state
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
End
,
offset:
Offset
.
zero
));
state
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
End
,
offset:
Offset
.
zero
));
...
@@ -12496,9 +12504,11 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
...
@@ -12496,9 +12504,11 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
expect
(
controller
.
selection
.
isCollapsed
,
false
);
expect
(
controller
.
selection
.
isCollapsed
,
false
);
expect
(
controller
.
selection
.
baseOffset
,
0
);
expect
(
controller
.
selection
.
baseOffset
,
0
);
expect
(
controller
.
selection
.
extentOffset
,
4
);
expect
(
controller
.
selection
.
extentOffset
,
4
);
expect
(
lastSelectionChangedCause
,
SelectionChangedCause
.
forcePress
);
lastSelectionChangedCause
=
null
;
// Now test using keyboard selection in a forwards direction.
// Now test using keyboard selection in a forwards direction.
controller
.
selection
=
const
TextSelection
.
collapsed
(
offset:
0
);
state
.
updateEditingValue
(
state
.
currentTextEditingValue
.
copyWith
(
selection:
const
TextSelection
.
collapsed
(
offset:
0
))
);
await
tester
.
pump
();
await
tester
.
pump
();
state
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
,
offset:
Offset
.
zero
));
state
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
,
offset:
Offset
.
zero
));
await
tester
.
pump
();
await
tester
.
pump
();
...
@@ -12523,7 +12533,7 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
...
@@ -12523,7 +12533,7 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
));
));
// Simulate UIKit setting the selection using keyboard selection.
// Simulate UIKit setting the selection using keyboard selection.
controller
.
selection
=
const
TextSelection
(
baseOffset:
0
,
extentOffset:
4
);
state
.
updateEditingValue
(
state
.
currentTextEditingValue
.
copyWith
(
selection:
const
TextSelection
(
baseOffset:
0
,
extentOffset:
4
))
);
await
tester
.
pump
();
await
tester
.
pump
();
state
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
End
,
offset:
Offset
.
zero
));
state
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
End
,
offset:
Offset
.
zero
));
...
@@ -12533,11 +12543,13 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
...
@@ -12533,11 +12543,13 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
expect
(
controller
.
selection
.
isCollapsed
,
false
);
expect
(
controller
.
selection
.
isCollapsed
,
false
);
expect
(
controller
.
selection
.
baseOffset
,
0
);
expect
(
controller
.
selection
.
baseOffset
,
0
);
expect
(
controller
.
selection
.
extentOffset
,
4
);
expect
(
controller
.
selection
.
extentOffset
,
4
);
expect
(
lastSelectionChangedCause
,
SelectionChangedCause
.
forcePress
);
lastSelectionChangedCause
=
null
;
// Test that the affinity is updated in case the floating cursor ends at the same offset.
// Test that the affinity is updated in case the floating cursor ends at the same offset.
// Put the selection at the beginning of the second line.
// Put the selection at the beginning of the second line.
controller
.
selection
=
const
TextSelection
.
collapsed
(
offset:
27
);
state
.
updateEditingValue
(
state
.
currentTextEditingValue
.
copyWith
(
selection:
const
TextSelection
.
collapsed
(
offset:
27
))
);
await
tester
.
pump
();
await
tester
.
pump
();
// Now test using keyboard selection in a forwards direction.
// Now test using keyboard selection in a forwards direction.
...
@@ -12572,6 +12584,8 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
...
@@ -12572,6 +12584,8 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
expect
(
controller
.
selection
.
isCollapsed
,
true
);
expect
(
controller
.
selection
.
isCollapsed
,
true
);
expect
(
controller
.
selection
.
baseOffset
,
27
);
expect
(
controller
.
selection
.
baseOffset
,
27
);
expect
(
controller
.
selection
.
extentOffset
,
27
);
expect
(
controller
.
selection
.
extentOffset
,
27
);
expect
(
lastSelectionChangedCause
,
SelectionChangedCause
.
forcePress
);
lastSelectionChangedCause
=
null
;
EditableText
.
debugDeterministicCursor
=
false
;
EditableText
.
debugDeterministicCursor
=
false
;
});
});
...
...
packages/flutter_test/lib/src/test_text_input.dart
View file @
e078c93b
...
@@ -296,6 +296,21 @@ class TestTextInput {
...
@@ -296,6 +296,21 @@ class TestTextInput {
);
);
}
}
/// Simulates a scribble interaction finishing.
Future
<
void
>
finishScribbleInteraction
()
async
{
assert
(
isRegistered
);
await
TestDefaultBinaryMessengerBinding
.
instance
.
defaultBinaryMessenger
.
handlePlatformMessage
(
SystemChannels
.
textInput
.
name
,
SystemChannels
.
textInput
.
codec
.
encodeMethodCall
(
MethodCall
(
'TextInputClient.scribbleInteractionFinished'
,
<
dynamic
>[
_client
??
-
1
,]
),
),
(
ByteData
?
data
)
{
/* response from framework is discarded */
},
);
}
/// Simulates a Scribble focus.
/// Simulates a Scribble focus.
Future
<
void
>
scribbleFocusElement
(
String
elementIdentifier
,
Offset
offset
)
async
{
Future
<
void
>
scribbleFocusElement
(
String
elementIdentifier
,
Offset
offset
)
async
{
assert
(
isRegistered
);
assert
(
isRegistered
);
...
...
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