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
52299fa3
Unverified
Commit
52299fa3
authored
Aug 03, 2020
by
Pierre-Louis
Committed by
GitHub
Aug 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache floating cursor location on start event instead of update (#62415)
parent
1513b971
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
41 deletions
+22
-41
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+15
-13
editable_text_cursor_test.dart
packages/flutter/test/widgets/editable_text_cursor_test.dart
+7
-28
No files found.
packages/flutter/lib/src/widgets/editable_text.dart
View file @
52299fa3
...
@@ -1623,7 +1623,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -1623,7 +1623,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
// cursor.
// cursor.
TextPosition
_lastTextPosition
;
TextPosition
_lastTextPosition
;
// The offset of the floating cursor as determined from the
first update
call.
// The offset of the floating cursor as determined from the
start
call.
Offset
_pointOffsetOrigin
;
Offset
_pointOffsetOrigin
;
// The most recent position of the floating cursor.
// The most recent position of the floating cursor.
...
@@ -1642,22 +1642,24 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
...
@@ -1642,22 +1642,24 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
_floatingCursorResetController
.
stop
();
_floatingCursorResetController
.
stop
();
_onFloatingCursorResetTick
();
_onFloatingCursorResetTick
();
}
}
// We want to send in points that are centered around a (0,0) origin, so
// we cache the position.
_pointOffsetOrigin
=
point
.
offset
;
final
TextPosition
currentTextPosition
=
TextPosition
(
offset:
renderEditable
.
selection
.
baseOffset
);
final
TextPosition
currentTextPosition
=
TextPosition
(
offset:
renderEditable
.
selection
.
baseOffset
);
_startCaretRect
=
renderEditable
.
getLocalRectForCaret
(
currentTextPosition
);
_startCaretRect
=
renderEditable
.
getLocalRectForCaret
(
currentTextPosition
);
renderEditable
.
setFloatingCursor
(
point
.
state
,
_startCaretRect
.
center
-
_floatingCursorOffset
,
currentTextPosition
);
_lastBoundedOffset
=
_startCaretRect
.
center
-
_floatingCursorOffset
;
_lastTextPosition
=
currentTextPosition
;
renderEditable
.
setFloatingCursor
(
point
.
state
,
_lastBoundedOffset
,
_lastTextPosition
);
break
;
break
;
case
FloatingCursorDragState
.
Update
:
case
FloatingCursorDragState
.
Update
:
// We want to send in points that are centered around a (0,0) origin, so we cache the
final
Offset
centeredPoint
=
point
.
offset
-
_pointOffsetOrigin
;
// position on the first update call.
final
Offset
rawCursorOffset
=
_startCaretRect
.
center
+
centeredPoint
-
_floatingCursorOffset
;
if
(
_pointOffsetOrigin
!=
null
)
{
final
Offset
centeredPoint
=
point
.
offset
-
_pointOffsetOrigin
;
_lastBoundedOffset
=
renderEditable
.
calculateBoundedFloatingCursorOffset
(
rawCursorOffset
);
final
Offset
rawCursorOffset
=
_startCaretRect
.
center
+
centeredPoint
-
_floatingCursorOffset
;
_lastTextPosition
=
renderEditable
.
getPositionForPoint
(
renderEditable
.
localToGlobal
(
_lastBoundedOffset
+
_floatingCursorOffset
));
_lastBoundedOffset
=
renderEditable
.
calculateBoundedFloatingCursorOffset
(
rawCursorOffset
);
renderEditable
.
setFloatingCursor
(
point
.
state
,
_lastBoundedOffset
,
_lastTextPosition
);
_lastTextPosition
=
renderEditable
.
getPositionForPoint
(
renderEditable
.
localToGlobal
(
_lastBoundedOffset
+
_floatingCursorOffset
));
renderEditable
.
setFloatingCursor
(
point
.
state
,
_lastBoundedOffset
,
_lastTextPosition
);
}
else
{
_pointOffsetOrigin
=
point
.
offset
;
}
break
;
break
;
case
FloatingCursorDragState
.
End
:
case
FloatingCursorDragState
.
End
:
// We skip animation if no update has happened.
// We skip animation if no update has happened.
...
...
packages/flutter/test/widgets/editable_text_cursor_test.dart
View file @
52299fa3
...
@@ -398,13 +398,9 @@ void main() {
...
@@ -398,13 +398,9 @@ void main() {
expect
(
controller
.
selection
.
baseOffset
,
29
);
expect
(
controller
.
selection
.
baseOffset
,
29
);
final
EditableTextState
editableTextState
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
final
EditableTextState
editableTextState
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
));
expect
(
controller
.
selection
.
baseOffset
,
29
);
// Sets the origin.
// Sets the origin.
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Update
,
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
,
offset:
const
Offset
(
20
,
20
)));
offset:
const
Offset
(
20
,
20
)));
expect
(
controller
.
selection
.
baseOffset
,
29
);
expect
(
controller
.
selection
.
baseOffset
,
29
);
...
@@ -427,10 +423,9 @@ void main() {
...
@@ -427,10 +423,9 @@ void main() {
expect
(
controller
.
selection
.
baseOffset
,
8
);
expect
(
controller
.
selection
.
baseOffset
,
8
);
// Go in the other direction.
// Go in the other direction.
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
));
// Sets the origin.
// Sets the origin.
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Update
,
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
,
offset:
const
Offset
(
20
,
20
)));
offset:
const
Offset
(
20
,
20
)));
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Update
,
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Update
,
offset:
const
Offset
(-
5000
,
20
)));
offset:
const
Offset
(-
5000
,
20
)));
...
@@ -482,13 +477,9 @@ void main() {
...
@@ -482,13 +477,9 @@ void main() {
expect
(
controller
.
selection
.
baseOffset
,
29
);
expect
(
controller
.
selection
.
baseOffset
,
29
);
final
EditableTextState
editableTextState
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
final
EditableTextState
editableTextState
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
));
expect
(
controller
.
selection
.
baseOffset
,
29
);
// Sets the origin.
// Sets the origin.
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Update
,
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
,
offset:
const
Offset
(
20
,
20
)));
offset:
const
Offset
(
20
,
20
)));
expect
(
controller
.
selection
.
baseOffset
,
29
);
expect
(
controller
.
selection
.
baseOffset
,
29
);
...
@@ -583,13 +574,9 @@ void main() {
...
@@ -583,13 +574,9 @@ void main() {
expect
(
controller
.
selection
.
baseOffset
,
29
);
expect
(
controller
.
selection
.
baseOffset
,
29
);
final
EditableTextState
editableTextState
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
final
EditableTextState
editableTextState
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
));
expect
(
controller
.
selection
.
baseOffset
,
29
);
// Sets the origin.
// Sets the origin.
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Update
,
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
,
offset:
const
Offset
(
20
,
20
)));
offset:
const
Offset
(
20
,
20
)));
expect
(
controller
.
selection
.
baseOffset
,
29
);
expect
(
controller
.
selection
.
baseOffset
,
29
);
...
@@ -603,13 +590,11 @@ void main() {
...
@@ -603,13 +590,11 @@ void main() {
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
End
));
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
End
));
// Immediately start a new floating cursor, in the same way as happens when
// Immediately start a new floating cursor, in the same way as happens when
// the user tries to select text in trackpad mode.
// the user tries to select text in trackpad mode.
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
));
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
,
offset:
const
Offset
(
20
,
20
)
));
await
tester
.
pumpAndSettle
();
await
tester
.
pumpAndSettle
();
// Set and move the second cursor like a selection. Previously, the second
// Set and move the second cursor like a selection. Previously, the second
// Update here caused a crash.
// Update here caused a crash.
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Update
,
offset:
const
Offset
(
20
,
20
)));
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Update
,
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Update
,
offset:
const
Offset
(-
250
,
20
)));
offset:
const
Offset
(-
250
,
20
)));
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
End
));
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
End
));
...
@@ -676,13 +661,7 @@ void main() {
...
@@ -676,13 +661,7 @@ void main() {
final
EditableTextState
editableTextState
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
final
EditableTextState
editableTextState
=
tester
.
firstState
(
find
.
byType
(
EditableText
));
editableTextState
.
updateFloatingCursor
(
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
),
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Start
,
offset:
const
Offset
(
20
,
20
)),
);
editableTextState
.
updateFloatingCursor
(
RawFloatingCursorPoint
(
state:
FloatingCursorDragState
.
Update
,
offset:
const
Offset
(
20
,
20
),
),
);
);
await
tester
.
pump
();
await
tester
.
pump
();
...
...
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