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
67841354
Unverified
Commit
67841354
authored
Dec 07, 2023
by
Kostia Sokolovskyi
Committed by
GitHub
Dec 07, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SelectionOverlay and TextSelectionOverlay should dispatch creation and disposal events. (#138804)
parent
b619b701
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
1 deletion
+108
-1
text_selection.dart
packages/flutter/lib/src/widgets/text_selection.dart
+30
-1
text_selection_test.dart
packages/flutter/test/widgets/text_selection_test.dart
+78
-0
No files found.
packages/flutter/lib/src/widgets/text_selection.dart
View file @
67841354
...
...
@@ -332,6 +332,15 @@ class TextSelectionOverlay {
required
TextMagnifierConfiguration
magnifierConfiguration
,
})
:
_handlesVisible
=
handlesVisible
,
_value
=
value
{
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if
(
kFlutterMemoryAllocationsEnabled
)
{
MemoryAllocations
.
instance
.
dispatchObjectCreated
(
library
:
'package:flutter/widgets.dart'
,
className:
'
$TextSelectionOverlay
'
,
object:
this
,
);
}
renderObject
.
selectionStartInViewport
.
addListener
(
_updateTextSelectionOverlayVisibilities
);
renderObject
.
selectionEndInViewport
.
addListener
(
_updateTextSelectionOverlayVisibilities
);
_updateTextSelectionOverlayVisibilities
();
...
...
@@ -585,6 +594,11 @@ class TextSelectionOverlay {
/// {@macro flutter.widgets.SelectionOverlay.dispose}
void
dispose
()
{
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if
(
kFlutterMemoryAllocationsEnabled
)
{
MemoryAllocations
.
instance
.
dispatchObjectDisposed
(
object:
this
);
}
_selectionOverlay
.
dispose
();
renderObject
.
selectionStartInViewport
.
removeListener
(
_updateTextSelectionOverlayVisibilities
);
renderObject
.
selectionEndInViewport
.
removeListener
(
_updateTextSelectionOverlayVisibilities
);
...
...
@@ -956,7 +970,17 @@ class SelectionOverlay {
_lineHeightAtEnd
=
lineHeightAtEnd
,
_selectionEndpoints
=
selectionEndpoints
,
_toolbarLocation
=
toolbarLocation
,
assert
(
debugCheckHasOverlay
(
context
));
assert
(
debugCheckHasOverlay
(
context
))
{
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if
(
kFlutterMemoryAllocationsEnabled
)
{
MemoryAllocations
.
instance
.
dispatchObjectCreated
(
library
:
'package:flutter/widgets.dart'
,
className:
'
$SelectionOverlay
'
,
object:
this
,
);
}
}
/// {@macro flutter.widgets.SelectionOverlay.context}
final
BuildContext
context
;
...
...
@@ -1506,6 +1530,11 @@ class SelectionOverlay {
/// Disposes this object and release resources.
/// {@endtemplate}
void
dispose
()
{
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if
(
kFlutterMemoryAllocationsEnabled
)
{
MemoryAllocations
.
instance
.
dispatchObjectDisposed
(
object:
this
);
}
hide
();
_magnifierInfo
.
dispose
();
}
...
...
packages/flutter/test/widgets/text_selection_test.dart
View file @
67841354
...
...
@@ -1242,6 +1242,19 @@ void main() {
);
}
testWidgetsWithLeakTracking
(
'dispatches memory events'
,
(
WidgetTester
tester
)
async
{
await
expectLater
(
await
memoryEvents
(
()
async
{
final
SelectionOverlay
overlay
=
await
pumpApp
(
tester
);
overlay
.
dispose
();
},
SelectionOverlay
,
),
areCreateAndDispose
,
);
});
testWidgetsWithLeakTracking
(
'can show and hide handles'
,
(
WidgetTester
tester
)
async
{
final
TextSelectionControlsSpy
spy
=
TextSelectionControlsSpy
();
final
SelectionOverlay
selectionOverlay
=
await
pumpApp
(
...
...
@@ -1703,6 +1716,71 @@ void main() {
expect
(
controller
.
selection
.
extentOffset
,
controller
.
text
.
length
);
expect
(
scrollController
.
position
.
pixels
,
scrollController
.
position
.
maxScrollExtent
);
});
group
(
'TextSelectionOverlay'
,
()
{
Future
<
TextSelectionOverlay
>
pumpApp
(
WidgetTester
tester
)
async
{
final
UniqueKey
column
=
UniqueKey
();
final
LayerLink
startHandleLayerLink
=
LayerLink
();
final
LayerLink
endHandleLayerLink
=
LayerLink
();
final
LayerLink
toolbarLayerLink
=
LayerLink
();
final
UniqueKey
editableText
=
UniqueKey
();
final
TextEditingController
controller
=
TextEditingController
();
addTearDown
(
controller
.
dispose
);
final
FocusNode
focusNode
=
FocusNode
();
addTearDown
(
focusNode
.
dispose
);
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Column
(
key:
column
,
children:
<
Widget
>[
FakeEditableText
(
key:
editableText
,
controller:
controller
,
focusNode:
focusNode
,
),
CompositedTransformTarget
(
link:
startHandleLayerLink
,
child:
const
Text
(
'start handle'
),
),
CompositedTransformTarget
(
link:
endHandleLayerLink
,
child:
const
Text
(
'end handle'
),
),
CompositedTransformTarget
(
link:
toolbarLayerLink
,
child:
const
Text
(
'toolbar'
),
),
],
),
));
return
TextSelectionOverlay
(
value:
TextEditingValue
.
empty
,
renderObject:
tester
.
state
<
EditableTextState
>(
find
.
byKey
(
editableText
)).
renderEditable
,
context:
tester
.
element
(
find
.
byKey
(
column
)),
onSelectionHandleTapped:
()
{},
startHandleLayerLink:
startHandleLayerLink
,
endHandleLayerLink:
endHandleLayerLink
,
selectionDelegate:
FakeTextSelectionDelegate
(),
toolbarLayerLink:
toolbarLayerLink
,
magnifierConfiguration:
TextMagnifierConfiguration
.
disabled
,
);
}
testWidgetsWithLeakTracking
(
'dispatches memory events'
,
(
WidgetTester
tester
)
async
{
await
expectLater
(
await
memoryEvents
(
()
async
{
final
TextSelectionOverlay
overlay
=
await
pumpApp
(
tester
);
overlay
.
dispose
();
},
TextSelectionOverlay
,
),
areCreateAndDispose
,
);
});
});
}
class
FakeTextSelectionGestureDetectorBuilderDelegate
implements
TextSelectionGestureDetectorBuilderDelegate
{
...
...
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