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
153f3d23
Unverified
Commit
153f3d23
authored
Nov 11, 2020
by
J-P Nurmi
Committed by
GitHub
Nov 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Editable(Text) shortcuts to respect read-only on desktop (#69891)
parent
22ec357b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
180 additions
and
2 deletions
+180
-2
editable.dart
packages/flutter/lib/src/rendering/editable.dart
+5
-2
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+175
-0
No files found.
packages/flutter/lib/src/rendering/editable.dart
View file @
153f3d23
...
...
@@ -776,7 +776,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
}
return
;
}
if
(
key
==
LogicalKeyboardKey
.
keyX
)
{
if
(
key
==
LogicalKeyboardKey
.
keyX
&&
!
_readOnly
)
{
if
(!
selection
!.
isCollapsed
)
{
Clipboard
.
setData
(
ClipboardData
(
text:
selection
!.
textInside
(
_plainText
)));
textSelectionDelegate
.
textEditingValue
=
TextEditingValue
(
...
...
@@ -787,7 +787,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
}
return
;
}
if
(
key
==
LogicalKeyboardKey
.
keyV
)
{
if
(
key
==
LogicalKeyboardKey
.
keyV
&&
!
_readOnly
)
{
// Snapshot the input before using `await`.
// See https://github.com/flutter/flutter/issues/11427
final
TextEditingValue
value
=
textSelectionDelegate
.
textEditingValue
;
...
...
@@ -818,6 +818,9 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
void
_handleDelete
({
required
bool
forward
})
{
assert
(
_selection
!=
null
);
if
(
_readOnly
)
{
return
;
}
String
textBefore
=
selection
!.
textBefore
(
_plainText
);
String
textAfter
=
selection
!.
textAfter
(
_plainText
);
int
cursorPosition
=
selection
!.
start
;
...
...
packages/flutter/test/widgets/editable_text_test.dart
View file @
153f3d23
...
...
@@ -4364,6 +4364,181 @@ void main() {
// On web, using keyboard for selection is handled by the browser.
},
skip:
kIsWeb
);
testWidgets
(
'keyboard shortcuts respect read-only'
,
(
WidgetTester
tester
)
async
{
final
String
platform
=
describeEnum
(
defaultTargetPlatform
).
toLowerCase
();
final
TextEditingController
controller
=
TextEditingController
(
text:
testText
);
controller
.
selection
=
const
TextSelection
(
baseOffset:
0
,
extentOffset:
testText
.
length
~/
2
,
affinity:
TextAffinity
.
upstream
,
);
TextSelection
?
selection
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Align
(
alignment:
Alignment
.
topLeft
,
child:
SizedBox
(
width:
400
,
child:
EditableText
(
readOnly:
true
,
controller:
controller
,
autofocus:
true
,
focusNode:
FocusNode
(),
style:
Typography
.
material2018
(
platform:
TargetPlatform
.
android
).
black
.
subtitle1
!,
cursorColor:
Colors
.
blue
,
backgroundCursorColor:
Colors
.
grey
,
selectionControls:
materialTextSelectionControls
,
keyboardType:
TextInputType
.
text
,
textAlign:
TextAlign
.
right
,
onSelectionChanged:
(
TextSelection
newSelection
,
SelectionChangedCause
?
newCause
)
{
selection
=
newSelection
;
},
),
),
),
));
await
tester
.
pump
();
// Wait for autofocus to take effect.
const
String
clipboardContent
=
'read-only'
;
await
Clipboard
.
setData
(
const
ClipboardData
(
text:
clipboardContent
));
// Paste
await
sendKeys
(
tester
,
<
LogicalKeyboardKey
>[
LogicalKeyboardKey
.
keyV
,
],
shortcutModifier:
true
,
platform:
platform
,
);
expect
(
selection
,
isNull
,
reason:
'on
$platform
'
);
expect
(
controller
.
text
,
equals
(
testText
),
reason:
'on
$platform
'
);
// Select All
await
sendKeys
(
tester
,
<
LogicalKeyboardKey
>[
LogicalKeyboardKey
.
keyA
,
],
shortcutModifier:
true
,
platform:
platform
,
);
expect
(
selection
!,
equals
(
const
TextSelection
(
baseOffset:
0
,
extentOffset:
testText
.
length
,
affinity:
TextAffinity
.
upstream
,
),
),
reason:
'on
$platform
'
,
);
expect
(
controller
.
text
,
equals
(
testText
),
reason:
'on
$platform
'
);
// Cut
await
sendKeys
(
tester
,
<
LogicalKeyboardKey
>[
LogicalKeyboardKey
.
keyX
,
],
shortcutModifier:
true
,
platform:
platform
,
);
expect
(
selection
!,
equals
(
const
TextSelection
(
baseOffset:
0
,
extentOffset:
testText
.
length
,
affinity:
TextAffinity
.
upstream
,
),
),
reason:
'on
$platform
'
,
);
expect
(
controller
.
text
,
equals
(
testText
),
reason:
'on
$platform
'
);
expect
(
(
await
Clipboard
.
getData
(
Clipboard
.
kTextPlain
))!.
text
,
equals
(
clipboardContent
),
reason:
'on
$platform
'
,
);
// Copy
await
sendKeys
(
tester
,
<
LogicalKeyboardKey
>[
LogicalKeyboardKey
.
keyC
,
],
shortcutModifier:
true
,
platform:
platform
,
);
expect
(
selection
!,
equals
(
const
TextSelection
(
baseOffset:
0
,
extentOffset:
testText
.
length
,
affinity:
TextAffinity
.
upstream
,
),
),
reason:
'on
$platform
'
,
);
expect
(
controller
.
text
,
equals
(
testText
),
reason:
'on
$platform
'
);
expect
(
(
await
Clipboard
.
getData
(
Clipboard
.
kTextPlain
))!.
text
,
equals
(
testText
),
reason:
'on
$platform
'
,
);
// Delete
await
sendKeys
(
tester
,
<
LogicalKeyboardKey
>[
LogicalKeyboardKey
.
delete
,
],
platform:
platform
,
);
expect
(
selection
!,
equals
(
const
TextSelection
(
baseOffset:
0
,
extentOffset:
testText
.
length
,
affinity:
TextAffinity
.
upstream
,
),
),
reason:
'on
$platform
'
,
);
expect
(
controller
.
text
,
equals
(
testText
),
reason:
'on
$platform
'
);
// Backspace
await
sendKeys
(
tester
,
<
LogicalKeyboardKey
>[
LogicalKeyboardKey
.
backspace
,
],
platform:
platform
,
);
expect
(
selection
!,
equals
(
const
TextSelection
(
baseOffset:
0
,
extentOffset:
testText
.
length
,
affinity:
TextAffinity
.
upstream
,
),
),
reason:
'on
$platform
'
,
);
expect
(
controller
.
text
,
equals
(
testText
),
reason:
'on
$platform
'
);
},
skip:
kIsWeb
,
variant:
TargetPlatformVariant
.
all
());
// Regression test for https://github.com/flutter/flutter/issues/31287
testWidgets
(
'text selection handle visibility'
,
(
WidgetTester
tester
)
async
{
// Text with two separate words to select.
...
...
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