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
24f0d285
Unverified
Commit
24f0d285
authored
Apr 22, 2021
by
Tomasz Gucio
Committed by
GitHub
Apr 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adjust selection drag start position for viewport offset changes (#80047)
parent
884fdf2e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
3 deletions
+56
-3
text_selection.dart
packages/flutter/lib/src/widgets/text_selection.dart
+14
-3
text_selection_test.dart
packages/flutter/test/widgets/text_selection_test.dart
+42
-0
No files found.
packages/flutter/lib/src/widgets/text_selection.dart
View file @
24f0d285
...
...
@@ -952,7 +952,7 @@ class TextSelectionGestureDetectorBuilder {
@protected
final
TextSelectionGestureDetectorBuilderDelegate
delegate
;
/// Returns true if
f
lastSecondaryTapDownPosition was on selection.
/// Returns true if lastSecondaryTapDownPosition was on selection.
bool
get
_lastSecondaryTapWasOnSelection
{
assert
(
renderEditable
.
lastSecondaryTapDownPosition
!=
null
);
if
(
renderEditable
.
selection
==
null
)
{
...
...
@@ -985,6 +985,9 @@ class TextSelectionGestureDetectorBuilder {
@protected
RenderEditable
get
renderEditable
=>
editableText
.
renderEditable
;
/// The viewport offset pixels of the [RenderEditable] at the last drag start.
double
_dragStartViewportOffset
=
0.0
;
/// Handler for [TextSelectionGestureDetector.onTapDown].
///
/// By default, it forwards the tap to [RenderEditable.handleTapDown] and sets
...
...
@@ -1197,6 +1200,8 @@ class TextSelectionGestureDetectorBuilder {
from:
details
.
globalPosition
,
cause:
SelectionChangedCause
.
drag
,
);
_dragStartViewportOffset
=
renderEditable
.
offset
.
pixels
;
}
/// Handler for [TextSelectionGestureDetector.onDragSelectionUpdate].
...
...
@@ -1212,8 +1217,14 @@ class TextSelectionGestureDetectorBuilder {
void
onDragSelectionUpdate
(
DragStartDetails
startDetails
,
DragUpdateDetails
updateDetails
)
{
if
(!
delegate
.
selectionEnabled
)
return
;
// Adjust the drag start offset for possible viewport offset changes.
final
Offset
startOffset
=
renderEditable
.
maxLines
==
1
?
Offset
(
renderEditable
.
offset
.
pixels
-
_dragStartViewportOffset
,
0.0
)
:
Offset
(
0.0
,
renderEditable
.
offset
.
pixels
-
_dragStartViewportOffset
);
renderEditable
.
selectPositionAt
(
from:
startDetails
.
globalPosition
,
from:
startDetails
.
globalPosition
-
startOffset
,
to:
updateDetails
.
globalPosition
,
cause:
SelectionChangedCause
.
drag
,
);
...
...
@@ -1618,7 +1629,7 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget
})
:
super
(
value
);
bool
_disposed
=
false
;
/// True if
f
this instance has been disposed.
/// True if this instance has been disposed.
bool
get
disposed
=>
_disposed
;
/// Check the [Clipboard] and update [value] if needed.
...
...
packages/flutter/test/widgets/text_selection_test.dart
View file @
24f0d285
...
...
@@ -624,6 +624,44 @@ void main() {
expect
(
editableText
.
selectionOverlay
!.
toolbarIsVisible
,
isFalse
);
});
testWidgets
(
'test TextSelectionGestureDetectorBuilder drag with RenderEditable viewport offset change'
,
(
WidgetTester
tester
)
async
{
await
pumpTextSelectionGestureDetectorBuilder
(
tester
);
final
FakeRenderEditable
renderEditable
=
tester
.
renderObject
(
find
.
byType
(
FakeEditable
));
// Reconfigure the RenderEditable for multi-line.
renderEditable
.
maxLines
=
null
;
renderEditable
.
offset
=
ViewportOffset
.
fixed
(
20.0
);
renderEditable
.
layout
(
const
BoxConstraints
.
tightFor
(
width:
400
,
height:
300.0
));
await
tester
.
pumpAndSettle
();
final
TestGesture
gesture
=
await
tester
.
startGesture
(
const
Offset
(
200.0
,
200.0
),
kind:
PointerDeviceKind
.
mouse
,
);
addTearDown
(
gesture
.
removePointer
);
await
tester
.
pumpAndSettle
();
expect
(
renderEditable
.
selectPositionAtCalled
,
isFalse
);
await
gesture
.
moveTo
(
const
Offset
(
300.0
,
200.0
));
await
tester
.
pumpAndSettle
();
expect
(
renderEditable
.
selectPositionAtCalled
,
isTrue
);
expect
(
renderEditable
.
selectPositionAtFrom
,
const
Offset
(
200.0
,
200.0
));
expect
(
renderEditable
.
selectPositionAtTo
,
const
Offset
(
300.0
,
200.0
));
// Move the viewport offset (scroll).
renderEditable
.
offset
=
ViewportOffset
.
fixed
(
150.0
);
renderEditable
.
layout
(
const
BoxConstraints
.
tightFor
(
width:
400
,
height:
300.0
));
await
tester
.
pumpAndSettle
();
await
gesture
.
moveTo
(
const
Offset
(
300.0
,
400.0
));
await
tester
.
pumpAndSettle
();
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
renderEditable
.
selectPositionAtCalled
,
isTrue
);
expect
(
renderEditable
.
selectPositionAtFrom
,
const
Offset
(
200.0
,
70.0
));
expect
(
renderEditable
.
selectPositionAtTo
,
const
Offset
(
300.0
,
400.0
));
});
testWidgets
(
'test TextSelectionGestureDetectorBuilder selection disabled'
,
(
WidgetTester
tester
)
async
{
await
pumpTextSelectionGestureDetectorBuilder
(
tester
,
selectionEnabled:
false
);
final
TestGesture
gesture
=
await
tester
.
startGesture
(
...
...
@@ -863,9 +901,13 @@ class FakeRenderEditable extends RenderEditable {
}
bool
selectPositionAtCalled
=
false
;
Offset
?
selectPositionAtFrom
;
Offset
?
selectPositionAtTo
;
@override
void
selectPositionAt
({
required
Offset
from
,
Offset
?
to
,
required
SelectionChangedCause
cause
})
{
selectPositionAtCalled
=
true
;
selectPositionAtFrom
=
from
;
selectPositionAtTo
=
to
;
}
bool
selectWordCalled
=
false
;
...
...
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