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
1794e81f
Unverified
Commit
1794e81f
authored
Feb 23, 2021
by
Justin McCandless
Committed by
GitHub
Feb 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Keep the selection after 'Copy' pressed on iOS. (#76327)
parent
df25cfe2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
9 deletions
+51
-9
text_selection.dart
packages/flutter/lib/src/cupertino/text_selection.dart
+1
-0
text_input.dart
packages/flutter/lib/src/services/text_input.dart
+5
-1
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+8
-2
text_selection.dart
packages/flutter/lib/src/widgets/text_selection.dart
+19
-5
text_selection_test.dart
packages/flutter/test/cupertino/text_selection_test.dart
+17
-0
editable_test.dart
packages/flutter/test/rendering/editable_test.dart
+1
-1
No files found.
packages/flutter/lib/src/cupertino/text_selection.dart
View file @
1794e81f
...
...
@@ -6,6 +6,7 @@ import 'dart:math' as math;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/services.dart'
;
import
'localizations.dart'
;
import
'text_selection_toolbar.dart'
;
...
...
packages/flutter/lib/src/services/text_input.dart
View file @
1794e81f
...
...
@@ -774,7 +774,11 @@ abstract class TextSelectionDelegate {
set
textEditingValue
(
TextEditingValue
value
);
/// Hides the text selection toolbar.
void
hideToolbar
();
///
/// By default, hideHandles is true, and the toolbar is hidden along with its
/// handles. If hideHandles is set to false, then the toolbar will be hidden
/// but the handles will remain.
void
hideToolbar
([
bool
hideHandles
=
true
]);
/// Brings the provided [TextPosition] into the visible area of the text
/// input.
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
1794e81f
...
...
@@ -2505,8 +2505,14 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
}
@override
void
hideToolbar
()
{
_selectionOverlay
?.
hide
();
void
hideToolbar
([
bool
hideHandles
=
true
])
{
if
(
hideHandles
)
{
// Hide the handles and the toolbar.
_selectionOverlay
?.
hide
();
}
else
{
// Hide only the toolbar but not the handles.
_selectionOverlay
?.
hideToolbar
();
}
}
/// Toggles the visibility of the toolbar.
...
...
packages/flutter/lib/src/widgets/text_selection.dart
View file @
1794e81f
...
...
@@ -228,12 +228,26 @@ abstract class TextSelectionControls {
text:
value
.
selection
.
textInside
(
value
.
text
),
));
clipboardStatus
?.
update
();
delegate
.
textEditingValue
=
TextEditingValue
(
text:
value
.
text
,
selection:
TextSelection
.
collapsed
(
offset:
value
.
selection
.
end
),
);
delegate
.
bringIntoView
(
delegate
.
textEditingValue
.
selection
.
extent
);
delegate
.
hideToolbar
();
switch
(
defaultTargetPlatform
)
{
case
TargetPlatform
.
iOS
:
// Hide the toolbar, but keep the selection and keep the handles.
delegate
.
hideToolbar
(
false
);
return
;
case
TargetPlatform
.
macOS
:
case
TargetPlatform
.
android
:
case
TargetPlatform
.
fuchsia
:
case
TargetPlatform
.
linux
:
case
TargetPlatform
.
windows
:
// Collapse the selection and hide the toolbar and handles.
delegate
.
textEditingValue
=
TextEditingValue
(
text:
value
.
text
,
selection:
TextSelection
.
collapsed
(
offset:
value
.
selection
.
end
),
);
delegate
.
hideToolbar
();
return
;
}
}
/// Paste the current clipboard selection (obtained from [Clipboard]) into
...
...
packages/flutter/test/cupertino/text_selection_test.dart
View file @
1794e81f
...
...
@@ -197,17 +197,34 @@ void main() {
await
tester
.
pump
(
const
Duration
(
milliseconds:
50
));
await
tester
.
tapAt
(
textOffsetToPosition
(
tester
,
index
));
await
tester
.
pumpAndSettle
();
expect
(
controller
.
selection
.
isCollapsed
,
isFalse
);
expect
(
controller
.
selection
.
baseOffset
,
0
);
expect
(
controller
.
selection
.
extentOffset
,
7
);
// Paste is showing even though clipboard is empty.
expect
(
find
.
text
(
'Paste'
),
findsOneWidget
);
expect
(
find
.
text
(
'Copy'
),
findsOneWidget
);
expect
(
find
.
text
(
'Cut'
),
findsOneWidget
);
expect
(
find
.
descendant
(
of:
find
.
byType
(
Overlay
),
matching:
find
.
byWidgetPredicate
((
Widget
w
)
=>
'
${w.runtimeType}
'
==
'_TextSelectionHandleOverlay'
),
),
findsNWidgets
(
2
));
// Tap copy to add something to the clipboard and close the menu.
await
tester
.
tapAt
(
tester
.
getCenter
(
find
.
text
(
'Copy'
)));
await
tester
.
pumpAndSettle
();
// The menu is gone, but the handles are visible on the existing selection.
expect
(
find
.
text
(
'Copy'
),
findsNothing
);
expect
(
find
.
text
(
'Cut'
),
findsNothing
);
expect
(
find
.
text
(
'Paste'
),
findsNothing
);
expect
(
controller
.
selection
.
isCollapsed
,
isFalse
);
expect
(
controller
.
selection
.
baseOffset
,
0
);
expect
(
controller
.
selection
.
extentOffset
,
7
);
expect
(
find
.
descendant
(
of:
find
.
byType
(
Overlay
),
matching:
find
.
byWidgetPredicate
((
Widget
w
)
=>
'
${w.runtimeType}
'
==
'_TextSelectionHandleOverlay'
),
),
findsNWidgets
(
2
));
// Double tap to show the menu again.
await
tester
.
tapAt
(
textOffsetToPosition
(
tester
,
index
));
...
...
packages/flutter/test/rendering/editable_test.dart
View file @
1794e81f
...
...
@@ -19,7 +19,7 @@ class FakeEditableTextState with TextSelectionDelegate {
TextEditingValue
textEditingValue
=
TextEditingValue
.
empty
;
@override
void
hideToolbar
()
{
}
void
hideToolbar
(
[
bool
hideHandles
=
true
]
)
{
}
@override
void
bringIntoView
(
TextPosition
position
)
{
}
...
...
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