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
9659db7b
Unverified
Commit
9659db7b
authored
Nov 11, 2021
by
smitsk
Committed by
GitHub
Nov 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix text cursor or input can be outside of the text field (#91698)
parent
77487319
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
6 deletions
+38
-6
text_painter.dart
packages/flutter/lib/src/painting/text_painter.dart
+2
-2
editable.dart
packages/flutter/lib/src/rendering/editable.dart
+9
-4
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+27
-0
No files found.
packages/flutter/lib/src/painting/text_painter.dart
View file @
9659db7b
...
...
@@ -780,7 +780,7 @@ class TextPainter {
final
double
caretEnd
=
box
.
end
;
final
double
dx
=
box
.
direction
==
TextDirection
.
rtl
?
caretEnd
-
caretPrototype
.
width
:
caretEnd
;
return
Rect
.
fromLTRB
(
min
(
dx
,
_paragraph
!.
width
),
box
.
top
,
min
(
dx
,
_paragraph
!.
width
),
box
.
bottom
);
return
Rect
.
fromLTRB
(
dx
.
clamp
(
0
,
_paragraph
!.
width
),
box
.
top
,
dx
.
clamp
(
0
,
_paragraph
!.
width
),
box
.
bottom
);
}
return
null
;
}
...
...
@@ -822,7 +822,7 @@ class TextPainter {
final
TextBox
box
=
boxes
.
last
;
final
double
caretStart
=
box
.
start
;
final
double
dx
=
box
.
direction
==
TextDirection
.
rtl
?
caretStart
-
caretPrototype
.
width
:
caretStart
;
return
Rect
.
fromLTRB
(
min
(
dx
,
_paragraph
!.
width
),
box
.
top
,
min
(
dx
,
_paragraph
!.
width
),
box
.
bottom
);
return
Rect
.
fromLTRB
(
dx
.
clamp
(
0
,
_paragraph
!.
width
),
box
.
top
,
dx
.
clamp
(
0
,
_paragraph
!.
width
),
box
.
bottom
);
}
return
null
;
}
...
...
packages/flutter/lib/src/rendering/editable.dart
View file @
9659db7b
...
...
@@ -1664,8 +1664,8 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
final
Offset
start
=
Offset
(
0.0
,
preferredLineHeight
)
+
caretOffset
+
paintOffset
;
return
<
TextSelectionPoint
>[
TextSelectionPoint
(
start
,
null
)];
}
else
{
final
Offset
start
=
Offset
(
boxes
.
first
.
start
,
boxes
.
first
.
bottom
)
+
paintOffset
;
final
Offset
end
=
Offset
(
boxes
.
last
.
end
,
boxes
.
last
.
bottom
)
+
paintOffset
;
final
Offset
start
=
Offset
(
boxes
.
first
.
start
.
clamp
(
0
,
_textPainter
.
size
.
width
)
,
boxes
.
first
.
bottom
)
+
paintOffset
;
final
Offset
end
=
Offset
(
boxes
.
last
.
end
.
clamp
(
0
,
_textPainter
.
size
.
width
)
,
boxes
.
last
.
bottom
)
+
paintOffset
;
return
<
TextSelectionPoint
>[
TextSelectionPoint
(
start
,
boxes
.
first
.
direction
),
TextSelectionPoint
(
end
,
boxes
.
last
.
direction
),
...
...
@@ -2741,14 +2741,19 @@ class _TextHighlightPainter extends RenderEditablePainter {
}
highlightPaint
.
color
=
color
;
final
List
<
TextBox
>
boxes
=
renderEditable
.
_textPainter
.
getBoxesForSelection
(
final
TextPainter
textPainter
=
renderEditable
.
_textPainter
;
final
List
<
TextBox
>
boxes
=
textPainter
.
getBoxesForSelection
(
TextSelection
(
baseOffset:
range
.
start
,
extentOffset:
range
.
end
),
boxHeightStyle:
selectionHeightStyle
,
boxWidthStyle:
selectionWidthStyle
,
);
for
(
final
TextBox
box
in
boxes
)
canvas
.
drawRect
(
box
.
toRect
().
shift
(
renderEditable
.
_paintOffset
),
highlightPaint
);
canvas
.
drawRect
(
box
.
toRect
().
shift
(
renderEditable
.
_paintOffset
)
.
intersect
(
Rect
.
fromLTWH
(
0
,
0
,
textPainter
.
width
,
textPainter
.
height
)),
highlightPaint
,
);
}
@override
...
...
packages/flutter/test/material/text_field_test.dart
View file @
9659db7b
...
...
@@ -1097,6 +1097,33 @@ void main() {
expect
(
cursorOffsetSpaces
.
dx
,
inputWidth
-
kCaretGap
);
});
testWidgets
(
'Overflowing a line with spaces stops the cursor at the end (rtl direction)'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
overlay
(
child:
const
TextField
(
textDirection:
TextDirection
.
rtl
,
maxLines:
null
,
),
),
);
const
String
testValueOneLine
=
'enough text to be exactly at the end of the line.'
;
const
String
testValueSpaces
=
'
$testValueOneLine
'
;
// Positioning the cursor at the end of a line overflowing with spaces puts
// it inside the input still.
await
tester
.
enterText
(
find
.
byType
(
TextField
),
testValueSpaces
);
await
skipPastScrollingAnimation
(
tester
);
await
tester
.
tapAt
(
textOffsetToPosition
(
tester
,
testValueSpaces
.
length
));
await
tester
.
pump
();
final
Offset
cursorOffsetSpaces
=
findRenderEditable
(
tester
).
getLocalRectForCaret
(
const
TextPosition
(
offset:
testValueSpaces
.
length
),
).
topLeft
;
expect
(
cursorOffsetSpaces
.
dx
>=
0
,
isTrue
);
});
testWidgets
(
'mobile obscureText control test'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
overlay
(
...
...
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