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
a4d570f0
Unverified
Commit
a4d570f0
authored
Jul 29, 2020
by
Justin McCandless
Committed by
GitHub
Jul 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SelectableText handles after Select All (#62072)
parent
f707f6f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
2 deletions
+90
-2
selectable_text.dart
packages/flutter/lib/src/material/selectable_text.dart
+17
-0
text_selection.dart
packages/flutter/lib/src/widgets/text_selection.dart
+0
-2
selectable_text_test.dart
packages/flutter/test/widgets/selectable_text_test.dart
+73
-0
No files found.
packages/flutter/lib/src/material/selectable_text.dart
View file @
a4d570f0
...
...
@@ -477,27 +477,44 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
_controller
=
_TextSpanEditingController
(
textSpan:
widget
.
textSpan
??
TextSpan
(
text:
widget
.
data
)
);
_controller
.
addListener
(
_onControllerChanged
);
}
@override
void
didUpdateWidget
(
SelectableText
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
if
(
widget
.
data
!=
oldWidget
.
data
||
widget
.
textSpan
!=
oldWidget
.
textSpan
)
{
_controller
.
removeListener
(
_onControllerChanged
);
_controller
=
_TextSpanEditingController
(
textSpan:
widget
.
textSpan
??
TextSpan
(
text:
widget
.
data
)
);
_controller
.
addListener
(
_onControllerChanged
);
}
if
(
_effectiveFocusNode
.
hasFocus
&&
_controller
.
selection
.
isCollapsed
)
{
_showSelectionHandles
=
false
;
}
else
{
_showSelectionHandles
=
true
;
}
}
@override
void
dispose
()
{
_focusNode
?.
dispose
();
_controller
.
removeListener
(
_onControllerChanged
);
super
.
dispose
();
}
void
_onControllerChanged
()
{
final
bool
showSelectionHandles
=
!
_effectiveFocusNode
.
hasFocus
||
!
_controller
.
selection
.
isCollapsed
;
if
(
showSelectionHandles
==
_showSelectionHandles
)
{
return
;
}
setState
(()
{
_showSelectionHandles
=
showSelectionHandles
;
});
}
void
_handleSelectionChanged
(
TextSelection
selection
,
SelectionChangedCause
cause
)
{
final
bool
willShowSelectionHandles
=
_shouldShowSelectionHandles
(
cause
);
if
(
willShowSelectionHandles
!=
_showSelectionHandles
)
{
...
...
packages/flutter/lib/src/widgets/text_selection.dart
View file @
a4d570f0
...
...
@@ -440,8 +440,6 @@ class TextSelectionOverlay {
OverlayEntry
(
builder:
(
BuildContext
context
)
=>
_buildHandle
(
context
,
_TextSelectionHandlePosition
.
end
)),
];
Overlay
.
of
(
context
,
rootOverlay:
true
,
debugRequiredFor:
debugRequiredFor
).
insertAll
(
_handles
);
}
...
...
packages/flutter/test/widgets/selectable_text_test.dart
View file @
a4d570f0
...
...
@@ -3894,4 +3894,77 @@ void main() {
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
text
);
});
testWidgets
(
'The handles show after pressing Select All'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
MaterialApp
(
home:
Material
(
child:
SelectableText
(
'abc def ghi'
),
),
),
);
// Long press at 'e' in 'def'.
final
Offset
ePos
=
textOffsetToPosition
(
tester
,
5
);
await
tester
.
longPressAt
(
ePos
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Select all'
),
findsOneWidget
);
expect
(
find
.
text
(
'Copy'
),
findsOneWidget
);
expect
(
find
.
text
(
'Paste'
),
findsNothing
);
expect
(
find
.
text
(
'Cut'
),
findsNothing
);
EditableTextState
editableText
=
tester
.
state
(
find
.
byType
(
EditableText
));
expect
(
editableText
.
selectionOverlay
.
handlesAreVisible
,
isTrue
);
expect
(
editableText
.
selectionOverlay
.
toolbarIsVisible
,
isTrue
);
await
tester
.
tap
(
find
.
text
(
'Select all'
));
await
tester
.
pump
();
expect
(
find
.
text
(
'Copy'
),
findsOneWidget
);
expect
(
find
.
text
(
'Select all'
),
findsNothing
);
expect
(
find
.
text
(
'Paste'
),
findsNothing
);
expect
(
find
.
text
(
'Cut'
),
findsNothing
);
editableText
=
tester
.
state
(
find
.
byType
(
EditableText
));
expect
(
editableText
.
selectionOverlay
.
handlesAreVisible
,
isTrue
);
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
android
,
TargetPlatform
.
fuchsia
,
TargetPlatform
.
linux
,
TargetPlatform
.
windows
,
}),
);
testWidgets
(
'The handles show after pressing Select All (iOS and Mac)'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
MaterialApp
(
home:
Material
(
child:
SelectableText
(
'abc def ghi'
),
),
),
);
// Long press at 'e' in 'def'.
final
Offset
ePos
=
textOffsetToPosition
(
tester
,
5
);
await
tester
.
longPressAt
(
ePos
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Select All'
),
findsOneWidget
);
expect
(
find
.
text
(
'Copy'
),
findsNothing
);
expect
(
find
.
text
(
'Paste'
),
findsNothing
);
expect
(
find
.
text
(
'Cut'
),
findsNothing
);
EditableTextState
editableText
=
tester
.
state
(
find
.
byType
(
EditableText
));
expect
(
editableText
.
selectionOverlay
.
handlesAreVisible
,
isFalse
);
expect
(
editableText
.
selectionOverlay
.
toolbarIsVisible
,
isTrue
);
await
tester
.
tap
(
find
.
text
(
'Select All'
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Copy'
),
findsOneWidget
);
expect
(
find
.
text
(
'Select All'
),
findsNothing
);
expect
(
find
.
text
(
'Paste'
),
findsNothing
);
expect
(
find
.
text
(
'Cut'
),
findsNothing
);
editableText
=
tester
.
state
(
find
.
byType
(
EditableText
));
expect
(
editableText
.
selectionOverlay
.
handlesAreVisible
,
isTrue
);
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
}),
);
}
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