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
384800b5
Unverified
Commit
384800b5
authored
May 19, 2022
by
Justin McCandless
Committed by
GitHub
May 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix right clicking a field to focus (#103228)
parent
0f23e96b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
137 additions
and
14 deletions
+137
-14
editable.dart
packages/flutter/lib/src/rendering/editable.dart
+1
-0
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+30
-14
text_field_test.dart
packages/flutter/test/cupertino/text_field_test.dart
+52
-0
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+54
-0
No files found.
packages/flutter/lib/src/rendering/editable.dart
View file @
384800b5
...
...
@@ -1958,6 +1958,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
extentOffset:
extentOffset
,
affinity:
fromPosition
.
affinity
,
);
_setSelection
(
newSelection
,
cause
);
}
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
384800b5
...
...
@@ -2441,6 +2441,23 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
_selectionOverlay
?.
updateForScroll
();
}
void
_createSelectionOverlay
()
{
_selectionOverlay
=
TextSelectionOverlay
(
clipboardStatus:
_clipboardStatus
,
context:
context
,
value:
_value
,
debugRequiredFor:
widget
,
toolbarLayerLink:
_toolbarLayerLink
,
startHandleLayerLink:
_startHandleLayerLink
,
endHandleLayerLink:
_endHandleLayerLink
,
renderObject:
renderEditable
,
selectionControls:
widget
.
selectionControls
,
selectionDelegate:
this
,
dragStartBehavior:
widget
.
dragStartBehavior
,
onSelectionHandleTapped:
widget
.
onSelectionHandleTapped
,
);
}
@pragma
(
'vm:notify-debugger-on-exception'
)
void
_handleSelectionChanged
(
TextSelection
selection
,
SelectionChangedCause
?
cause
)
{
// We return early if the selection is not valid. This can happen when the
...
...
@@ -2478,20 +2495,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
_selectionOverlay
=
null
;
}
else
{
if
(
_selectionOverlay
==
null
)
{
_selectionOverlay
=
TextSelectionOverlay
(
clipboardStatus:
_clipboardStatus
,
context:
context
,
value:
_value
,
debugRequiredFor:
widget
,
toolbarLayerLink:
_toolbarLayerLink
,
startHandleLayerLink:
_startHandleLayerLink
,
endHandleLayerLink:
_endHandleLayerLink
,
renderObject:
renderEditable
,
selectionControls:
widget
.
selectionControls
,
selectionDelegate:
this
,
dragStartBehavior:
widget
.
dragStartBehavior
,
onSelectionHandleTapped:
widget
.
onSelectionHandleTapped
,
);
_createSelectionOverlay
();
}
else
{
_selectionOverlay
!.
update
(
_value
);
}
...
...
@@ -2943,6 +2947,18 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
if
(
shouldShowCaret
)
{
_scheduleShowCaretOnScreen
(
withAnimation:
true
);
}
// Even if the value doesn't change, it may be necessary to focus and build
// the selection overlay. For example, this happens when right clicking an
// unfocused field that previously had a selection in the same spot.
if
(
value
==
textEditingValue
)
{
if
(!
widget
.
focusNode
.
hasFocus
)
{
widget
.
focusNode
.
requestFocus
();
_createSelectionOverlay
();
}
return
;
}
_formatAndSetValue
(
value
,
cause
,
userInteraction:
true
);
}
...
...
packages/flutter/test/cupertino/text_field_test.dart
View file @
384800b5
...
...
@@ -5663,4 +5663,56 @@ void main() {
variant:
TargetPlatformVariant
.
all
(),
skip:
isContextMenuProvidedByPlatform
,
// [intended] only applies to platforms where we supply the context menu.
);
testWidgets
(
'Can right click to focus multiple times'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/pull/103228
final
FocusNode
focusNode1
=
FocusNode
();
final
FocusNode
focusNode2
=
FocusNode
();
final
UniqueKey
key1
=
UniqueKey
();
final
UniqueKey
key2
=
UniqueKey
();
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
Column
(
children:
<
Widget
>[
CupertinoTextField
(
key:
key1
,
focusNode:
focusNode1
,
),
CupertinoTextField
(
key:
key2
,
focusNode:
focusNode2
,
),
],
),
),
);
// Interact with the field to establish the input connection.
await
tester
.
tapAt
(
tester
.
getCenter
(
find
.
byKey
(
key1
)),
buttons:
kSecondaryMouseButton
,
);
await
tester
.
pump
();
expect
(
focusNode1
.
hasFocus
,
isTrue
);
expect
(
focusNode2
.
hasFocus
,
isFalse
);
await
tester
.
tapAt
(
tester
.
getCenter
(
find
.
byKey
(
key2
)),
buttons:
kSecondaryMouseButton
,
);
await
tester
.
pump
();
expect
(
focusNode1
.
hasFocus
,
isFalse
);
expect
(
focusNode2
.
hasFocus
,
isTrue
);
await
tester
.
tapAt
(
tester
.
getCenter
(
find
.
byKey
(
key1
)),
buttons:
kSecondaryMouseButton
,
);
await
tester
.
pump
();
expect
(
focusNode1
.
hasFocus
,
isTrue
);
expect
(
focusNode2
.
hasFocus
,
isFalse
);
});
}
packages/flutter/test/material/text_field_test.dart
View file @
384800b5
...
...
@@ -11399,4 +11399,58 @@ void main() {
variant:
TargetPlatformVariant
.
all
(),
skip:
isContextMenuProvidedByPlatform
,
// [intended] only applies to platforms where we supply the context menu.
);
testWidgets
(
'Can right click to focus multiple times'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/pull/103228
final
FocusNode
focusNode1
=
FocusNode
();
final
FocusNode
focusNode2
=
FocusNode
();
final
UniqueKey
key1
=
UniqueKey
();
final
UniqueKey
key2
=
UniqueKey
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
Column
(
children:
<
Widget
>[
TextField
(
key:
key1
,
focusNode:
focusNode1
,
),
TextField
(
key:
key2
,
focusNode:
focusNode2
,
),
],
),
),
),
);
// Interact with the field to establish the input connection.
await
tester
.
tapAt
(
tester
.
getCenter
(
find
.
byKey
(
key1
)),
buttons:
kSecondaryButton
,
);
await
tester
.
pump
();
expect
(
focusNode1
.
hasFocus
,
isTrue
);
expect
(
focusNode2
.
hasFocus
,
isFalse
);
await
tester
.
tapAt
(
tester
.
getCenter
(
find
.
byKey
(
key2
)),
buttons:
kSecondaryButton
,
);
await
tester
.
pump
();
expect
(
focusNode1
.
hasFocus
,
isFalse
);
expect
(
focusNode2
.
hasFocus
,
isTrue
);
await
tester
.
tapAt
(
tester
.
getCenter
(
find
.
byKey
(
key1
)),
buttons:
kSecondaryButton
,
);
await
tester
.
pump
();
expect
(
focusNode1
.
hasFocus
,
isTrue
);
expect
(
focusNode2
.
hasFocus
,
isFalse
);
});
}
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