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
7675a6ea
Unverified
Commit
7675a6ea
authored
Mar 22, 2019
by
Mouad Debbar
Committed by
GitHub
Mar 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for text selection via mouse to Cupertino text fields (#29769)
parent
bfa1d25b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
5 deletions
+123
-5
text_field.dart
packages/flutter/lib/src/cupertino/text_field.dart
+25
-0
text_field.dart
packages/flutter/lib/src/material/text_field.dart
+4
-4
text_field_test.dart
packages/flutter/test/cupertino/text_field_test.dart
+94
-1
No files found.
packages/flutter/lib/src/cupertino/text_field.dart
View file @
7675a6ea
...
...
@@ -533,6 +533,28 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
_editableTextKey
.
currentState
.
showToolbar
();
}
void
_handleMouseDragSelectionStart
(
DragStartDetails
details
)
{
_renderEditable
.
selectPositionAt
(
from:
details
.
globalPosition
,
cause:
SelectionChangedCause
.
drag
,
);
}
void
_handleMouseDragSelectionUpdate
(
DragStartDetails
startDetails
,
DragUpdateDetails
updateDetails
,
)
{
_renderEditable
.
selectPositionAt
(
from:
startDetails
.
globalPosition
,
to:
updateDetails
.
globalPosition
,
cause:
SelectionChangedCause
.
drag
,
);
}
void
_handleMouseDragSelectionEnd
(
DragEndDetails
details
)
{
_requestKeyboard
();
}
void
_handleSelectionChanged
(
TextSelection
selection
,
SelectionChangedCause
cause
)
{
if
(
cause
==
SelectionChangedCause
.
longPress
)
{
_editableTextKey
.
currentState
?.
bringIntoView
(
selection
.
base
);
...
...
@@ -742,6 +764,9 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
onSingleLongTapMoveUpdate:
_handleSingleLongTapMoveUpdate
,
onSingleLongTapEnd:
_handleSingleLongTapEnd
,
onDoubleTapDown:
_handleDoubleTapDown
,
onDragSelectionStart:
_handleMouseDragSelectionStart
,
onDragSelectionUpdate:
_handleMouseDragSelectionUpdate
,
onDragSelectionEnd:
_handleMouseDragSelectionEnd
,
behavior:
HitTestBehavior
.
translucent
,
child:
_addTextDependentAttachments
(
paddedEditable
,
textStyle
),
),
...
...
packages/flutter/lib/src/material/text_field.dart
View file @
7675a6ea
...
...
@@ -743,7 +743,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
}
}
void
_handleDragSelectionStart
(
DragStartDetails
details
)
{
void
_handle
Mouse
DragSelectionStart
(
DragStartDetails
details
)
{
_renderEditable
.
selectPositionAt
(
from:
details
.
globalPosition
,
cause:
SelectionChangedCause
.
drag
,
...
...
@@ -751,7 +751,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
_startSplash
(
details
.
globalPosition
);
}
void
_handleDragSelectionUpdate
(
void
_handle
Mouse
DragSelectionUpdate
(
DragStartDetails
startDetails
,
DragUpdateDetails
updateDetails
,
)
{
...
...
@@ -930,8 +930,8 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
onSingleLongTapMoveUpdate:
_handleSingleLongTapMoveUpdate
,
onSingleLongTapEnd:
_handleSingleLongTapEnd
,
onDoubleTapDown:
_handleDoubleTapDown
,
onDragSelectionStart:
_handleDragSelectionStart
,
onDragSelectionUpdate:
_handleDragSelectionUpdate
,
onDragSelectionStart:
_handle
Mouse
DragSelectionStart
,
onDragSelectionUpdate:
_handle
Mouse
DragSelectionUpdate
,
behavior:
HitTestBehavior
.
translucent
,
child:
child
,
),
...
...
packages/flutter/test/cupertino/text_field_test.dart
View file @
7675a6ea
...
...
@@ -8,7 +8,7 @@ import 'package:flutter/cupertino.dart';
import
'package:flutter/rendering.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/gestures.dart'
show
DragStartBehavior
;
import
'package:flutter/gestures.dart'
show
DragStartBehavior
,
PointerDeviceKind
;
import
'package:flutter_test/flutter_test.dart'
;
class
MockClipboard
{
...
...
@@ -1791,6 +1791,99 @@ void main() {
expect
(
controller
.
selection
.
extentOffset
,
5
);
});
testWidgets
(
'Can select text by dragging with a mouse'
,
(
WidgetTester
tester
)
async
{
final
TextEditingController
controller
=
TextEditingController
();
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
Center
(
child:
CupertinoTextField
(
dragStartBehavior:
DragStartBehavior
.
down
,
controller:
controller
,
style:
const
TextStyle
(
fontFamily:
'Ahem'
,
fontSize:
10.0
,
),
),
),
),
);
const
String
testValue
=
'abc def ghi'
;
await
tester
.
enterText
(
find
.
byType
(
CupertinoTextField
),
testValue
);
// Skip past scrolling animation.
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
milliseconds:
200
));
final
Offset
ePos
=
textOffsetToPosition
(
tester
,
testValue
.
indexOf
(
'e'
));
final
Offset
gPos
=
textOffsetToPosition
(
tester
,
testValue
.
indexOf
(
'g'
));
final
TestGesture
gesture
=
await
tester
.
startGesture
(
ePos
,
kind:
PointerDeviceKind
.
mouse
);
await
tester
.
pump
();
await
gesture
.
moveTo
(
gPos
);
await
tester
.
pump
();
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
controller
.
selection
.
baseOffset
,
testValue
.
indexOf
(
'e'
));
expect
(
controller
.
selection
.
extentOffset
,
testValue
.
indexOf
(
'g'
));
});
testWidgets
(
'Continuous dragging does not cause flickering'
,
(
WidgetTester
tester
)
async
{
int
selectionChangedCount
=
0
;
const
String
testValue
=
'abc def ghi'
;
final
TextEditingController
controller
=
TextEditingController
(
text:
testValue
);
controller
.
addListener
(()
{
selectionChangedCount
++;
});
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
Center
(
child:
CupertinoTextField
(
dragStartBehavior:
DragStartBehavior
.
down
,
controller:
controller
,
style:
const
TextStyle
(
fontFamily:
'Ahem'
,
fontSize:
10.0
,
),
),
),
),
);
final
Offset
cPos
=
textOffsetToPosition
(
tester
,
2
);
// Index of 'c'.
final
Offset
gPos
=
textOffsetToPosition
(
tester
,
8
);
// Index of 'g'.
final
Offset
hPos
=
textOffsetToPosition
(
tester
,
9
);
// Index of 'h'.
// Drag from 'c' to 'g'.
final
TestGesture
gesture
=
await
tester
.
startGesture
(
cPos
,
kind:
PointerDeviceKind
.
mouse
);
await
tester
.
pump
();
await
gesture
.
moveTo
(
gPos
);
await
tester
.
pumpAndSettle
();
expect
(
selectionChangedCount
,
isNonZero
);
selectionChangedCount
=
0
;
expect
(
controller
.
selection
.
baseOffset
,
2
);
expect
(
controller
.
selection
.
extentOffset
,
8
);
// Tiny movement shouldn't cause text selection to change.
await
gesture
.
moveTo
(
gPos
+
const
Offset
(
4.0
,
0.0
));
await
tester
.
pumpAndSettle
();
expect
(
selectionChangedCount
,
0
);
// Now a text selection change will occur after a significant movement.
await
gesture
.
moveTo
(
hPos
);
await
tester
.
pump
();
await
gesture
.
up
();
await
tester
.
pumpAndSettle
();
expect
(
selectionChangedCount
,
1
);
expect
(
controller
.
selection
.
baseOffset
,
2
);
expect
(
controller
.
selection
.
extentOffset
,
9
);
});
testWidgets
(
'text field respects theme'
,
(
WidgetTester
tester
)
async
{
...
...
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