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
8b46014e
Unverified
Commit
8b46014e
authored
Jan 13, 2022
by
Justin McCandless
Committed by
GitHub
Jan 13, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mac cmd + shift + left/right (#95948)
parent
06515fe0
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
450 additions
and
25 deletions
+450
-25
text_editing.dart
packages/flutter/lib/src/services/text_editing.dart
+2
-2
default_text_editing_shortcuts.dart
...utter/lib/src/widgets/default_text_editing_shortcuts.dart
+2
-2
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+25
-0
text_editing_intents.dart
packages/flutter/lib/src/widgets/text_editing_intents.dart
+31
-7
editable_text_test.dart
packages/flutter/test/widgets/editable_text_test.dart
+390
-14
No files found.
packages/flutter/lib/src/services/text_editing.dart
View file @
8b46014e
...
...
@@ -238,8 +238,8 @@ class TextSelection extends TextRange {
/// [TextSelection.extentOffset] to the given [TextPosition].
///
/// In some cases, the [TextSelection.baseOffset] and
/// [TextSelection.extentOffset] may flip during this operation,
or the siz
e
/// of the selection may shrink.
/// [TextSelection.extentOffset] may flip during this operation,
and/or th
e
///
size
of the selection may shrink.
///
/// ## Difference with [expandTo]
/// In contrast with this method, [expandTo] is strictly growth; the
...
...
packages/flutter/lib/src/widgets/default_text_editing_shortcuts.dart
View file @
8b46014e
...
...
@@ -307,8 +307,8 @@ class DefaultTextEditingShortcuts extends Shortcuts {
const
SingleActivator
(
LogicalKeyboardKey
.
arrowUp
,
meta:
true
):
const
ExtendSelectionToDocumentBoundaryIntent
(
forward:
false
,
collapseSelection:
true
),
const
SingleActivator
(
LogicalKeyboardKey
.
arrowDown
,
meta:
true
):
const
ExtendSelectionToDocumentBoundaryIntent
(
forward:
true
,
collapseSelection:
true
),
const
SingleActivator
(
LogicalKeyboardKey
.
arrowLeft
,
shift:
true
,
meta:
true
):
const
Ex
tendSelectionToLineBreakIntent
(
forward:
false
,
collapseSelection
:
false
),
const
SingleActivator
(
LogicalKeyboardKey
.
arrowRight
,
shift:
true
,
meta:
true
):
const
Ex
tendSelectionToLineBreakIntent
(
forward:
true
,
collapseSelection:
fals
e
),
const
SingleActivator
(
LogicalKeyboardKey
.
arrowLeft
,
shift:
true
,
meta:
true
):
const
Ex
pandSelectionToLineBreakIntent
(
forward
:
false
),
const
SingleActivator
(
LogicalKeyboardKey
.
arrowRight
,
shift:
true
,
meta:
true
):
const
Ex
pandSelectionToLineBreakIntent
(
forward:
tru
e
),
const
SingleActivator
(
LogicalKeyboardKey
.
arrowUp
,
shift:
true
,
meta:
true
):
const
ExtendSelectionToDocumentBoundaryIntent
(
forward:
false
,
collapseSelection:
false
),
const
SingleActivator
(
LogicalKeyboardKey
.
arrowDown
,
shift:
true
,
meta:
true
):
const
ExtendSelectionToDocumentBoundaryIntent
(
forward:
true
,
collapseSelection:
false
),
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
8b46014e
...
...
@@ -2931,6 +2931,30 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
late
final
_UpdateTextSelectionToAdjacentLineAction
<
ExtendSelectionVerticallyToAdjacentLineIntent
>
_adjacentLineAction
=
_UpdateTextSelectionToAdjacentLineAction
<
ExtendSelectionVerticallyToAdjacentLineIntent
>(
this
);
void
_expandSelection
(
ExpandSelectionToLineBreakIntent
intent
)
{
final
_TextBoundary
textBoundary
=
_linebreak
(
intent
);
final
TextSelection
textBoundarySelection
=
textBoundary
.
textEditingValue
.
selection
;
if
(!
textBoundarySelection
.
isValid
)
{
return
;
}
final
bool
inOrder
=
textBoundarySelection
.
baseOffset
<=
textBoundarySelection
.
extentOffset
;
final
bool
towardsExtent
=
intent
.
forward
==
inOrder
;
final
TextPosition
position
=
towardsExtent
?
textBoundarySelection
.
extent
:
textBoundarySelection
.
base
;
final
TextPosition
newExtent
=
intent
.
forward
?
textBoundary
.
getTrailingTextBoundaryAt
(
position
)
:
textBoundary
.
getLeadingTextBoundaryAt
(
position
);
final
TextSelection
newSelection
=
textBoundarySelection
.
expandTo
(
newExtent
,
textBoundarySelection
.
isCollapsed
);
userUpdateTextEditingValue
(
_value
.
copyWith
(
selection:
newSelection
),
SelectionChangedCause
.
keyboard
,
);
}
late
final
Map
<
Type
,
Action
<
Intent
>>
_actions
=
<
Type
,
Action
<
Intent
>>{
DoNothingAndStopPropagationTextIntent:
DoNothingAction
(
consumesKey:
false
),
ReplaceTextIntent:
_replaceTextAction
,
...
...
@@ -2946,6 +2970,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
ExtendSelectionByCharacterIntent:
_makeOverridable
(
_UpdateTextSelectionAction
<
ExtendSelectionByCharacterIntent
>(
this
,
false
,
_characterBoundary
,)),
ExtendSelectionToNextWordBoundaryIntent:
_makeOverridable
(
_UpdateTextSelectionAction
<
ExtendSelectionToNextWordBoundaryIntent
>(
this
,
true
,
_nextWordBoundary
)),
ExtendSelectionToLineBreakIntent:
_makeOverridable
(
_UpdateTextSelectionAction
<
ExtendSelectionToLineBreakIntent
>(
this
,
true
,
_linebreak
)),
ExpandSelectionToLineBreakIntent:
_makeOverridable
(
CallbackAction
<
ExpandSelectionToLineBreakIntent
>(
onInvoke:
_expandSelection
)),
ExtendSelectionVerticallyToAdjacentLineIntent:
_makeOverridable
(
_adjacentLineAction
),
ExtendSelectionToDocumentBoundaryIntent:
_makeOverridable
(
_UpdateTextSelectionAction
<
ExtendSelectionToDocumentBoundaryIntent
>(
this
,
true
,
_documentBoundary
)),
ExtendSelectionToNextWordBoundaryOrCaretLocationIntent:
_makeOverridable
(
_ExtendSelectionOrCaretPositionAction
(
this
,
_nextWordBoundary
)),
...
...
packages/flutter/lib/src/widgets/text_editing_intents.dart
View file @
8b46014e
...
...
@@ -92,7 +92,7 @@ abstract class DirectionalCaretMovementIntent extends DirectionalTextEditingInte
final
bool
collapseAtReversal
;
}
/// Ex
pa
nds, or moves the current selection from the current
/// Ex
te
nds, or moves the current selection from the current
/// [TextSelection.extent] position to the previous or the next character
/// boundary.
class
ExtendSelectionByCharacterIntent
extends
DirectionalCaretMovementIntent
{
...
...
@@ -103,7 +103,7 @@ class ExtendSelectionByCharacterIntent extends DirectionalCaretMovementIntent {
})
:
super
(
forward
,
collapseSelection
);
}
/// Ex
pa
nds, or moves the current selection from the current
/// Ex
te
nds, or moves the current selection from the current
/// [TextSelection.extent] position to the previous or the next word
/// boundary.
class
ExtendSelectionToNextWordBoundaryIntent
extends
DirectionalCaretMovementIntent
{
...
...
@@ -114,7 +114,7 @@ class ExtendSelectionToNextWordBoundaryIntent extends DirectionalCaretMovementIn
})
:
super
(
forward
,
collapseSelection
);
}
/// Ex
pa
nds, or moves the current selection from the current
/// Ex
te
nds, or moves the current selection from the current
/// [TextSelection.extent] position to the previous or the next word
/// boundary, or the [TextSelection.base] position if it's closer in the move
/// direction.
...
...
@@ -124,7 +124,7 @@ class ExtendSelectionToNextWordBoundaryIntent extends DirectionalCaretMovementIn
/// when the order of [TextSelection.base] and [TextSelection.extent] would
/// reverse.
///
/// This is typically only used on
m
acOS.
/// This is typically only used on
M
acOS.
class
ExtendSelectionToNextWordBoundaryOrCaretLocationIntent
extends
DirectionalTextEditingIntent
{
/// Creates an [ExtendSelectionToNextWordBoundaryOrCaretLocationIntent].
const
ExtendSelectionToNextWordBoundaryOrCaretLocationIntent
({
...
...
@@ -132,9 +132,33 @@ class ExtendSelectionToNextWordBoundaryOrCaretLocationIntent extends Directional
})
:
super
(
forward
);
}
/// Expands, or moves the current selection from the current
/// Expands the current selection to the closest line break in the direction
/// given by [forward].
///
/// Either the base or extent can move, whichever is closer to the line break.
/// The selection will never shrink.
///
/// This behavior is common on MacOS.
///
/// See also:
///
/// [ExtendSelectionToLineBreakIntent], which is similar but always moves the
/// extent.
class
ExpandSelectionToLineBreakIntent
extends
DirectionalTextEditingIntent
{
/// Creates an [ExpandSelectionToLineBreakIntent].
const
ExpandSelectionToLineBreakIntent
({
required
bool
forward
,
})
:
super
(
forward
);
}
/// Extends, or moves the current selection from the current
/// [TextSelection.extent] position to the closest line break in the direction
/// given by [forward].
///
/// See also:
///
/// [ExpandSelectionToLineBreakIntent], which is similar but always increases
/// the size of the selection.
class
ExtendSelectionToLineBreakIntent
extends
DirectionalCaretMovementIntent
{
/// Creates an [ExtendSelectionToLineBreakIntent].
const
ExtendSelectionToLineBreakIntent
({
...
...
@@ -145,7 +169,7 @@ class ExtendSelectionToLineBreakIntent extends DirectionalCaretMovementIntent {
super
(
forward
,
collapseSelection
,
collapseAtReversal
);
}
/// Ex
pa
nds, or moves the current selection from the current
/// Ex
te
nds, or moves the current selection from the current
/// [TextSelection.extent] position to the closest position on the adjacent
/// line.
class
ExtendSelectionVerticallyToAdjacentLineIntent
extends
DirectionalCaretMovementIntent
{
...
...
@@ -156,7 +180,7 @@ class ExtendSelectionVerticallyToAdjacentLineIntent extends DirectionalCaretMove
})
:
super
(
forward
,
collapseSelection
);
}
/// Ex
pa
nds, or moves the current selection from the current
/// Ex
te
nds, or moves the current selection from the current
/// [TextSelection.extent] position to the start or the end of the document.
class
ExtendSelectionToDocumentBoundaryIntent
extends
DirectionalCaretMovementIntent
{
/// Creates an [ExtendSelectionToDocumentBoundaryIntent].
...
...
packages/flutter/test/widgets/editable_text_test.dart
View file @
8b46014e
This diff is collapsed.
Click to expand it.
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