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
c1057084
Unverified
Commit
c1057084
authored
Jun 23, 2020
by
Justin McCandless
Committed by
GitHub
Jun 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RTL caret position (#60009)
parent
fc64e75a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
4 deletions
+65
-4
text_painter.dart
packages/flutter/lib/src/painting/text_painter.dart
+3
-0
text_field_test.dart
packages/flutter/test/material/text_field_test.dart
+62
-4
No files found.
packages/flutter/lib/src/painting/text_painter.dart
View file @
c1057084
...
...
@@ -563,6 +563,9 @@ class TextPainter {
}
_lastMinWidth
=
minWidth
;
_lastMaxWidth
=
maxWidth
;
// A change in layout invalidates the cached caret metrics as well.
_previousCaretPosition
=
null
;
_previousCaretPrototype
=
null
;
_paragraph
.
layout
(
ui
.
ParagraphConstraints
(
width:
maxWidth
));
if
(
minWidth
!=
maxWidth
)
{
final
double
newWidth
=
maxIntrinsicWidth
.
clamp
(
minWidth
,
maxWidth
)
as
double
;
...
...
packages/flutter/test/material/text_field_test.dart
View file @
c1057084
...
...
@@ -143,6 +143,8 @@ void main() {
const
String
kMoreThanFourLines
=
kThreeLines
+
"
\n
Fourth line won't display and ends at"
;
// Gap between caret and edge of input, defined in editable.dart.
const
int
kCaretGap
=
1
;
setUp
(()
async
{
debugResetSemanticsIdCounter
();
...
...
@@ -754,10 +756,7 @@ void main() {
const
TextPosition
(
offset:
testValueSpaces
.
length
),
).
bottomRight
;
// Gap between caret and edge of input, defined in editable.dart.
const
int
_kCaretGap
=
1
;
expect
(
cursorOffsetSpaces
.
dx
,
inputWidth
-
_kCaretGap
);
expect
(
cursorOffsetSpaces
.
dx
,
inputWidth
-
kCaretGap
);
});
testWidgets
(
'mobile obscureText control test'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -8011,4 +8010,63 @@ void main() {
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
basic
);
await
gesture
.
moveTo
(
center
);
});
testWidgets
(
'Caret rtl with changing width'
,
(
WidgetTester
tester
)
async
{
StateSetter
setState
;
bool
isWide
=
false
;
const
double
wideWidth
=
300.0
;
const
double
narrowWidth
=
200.0
;
final
TextEditingController
controller
=
TextEditingController
();
await
tester
.
pumpWidget
(
boilerplate
(
child:
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setter
)
{
setState
=
setter
;
return
Container
(
width:
isWide
?
wideWidth
:
narrowWidth
,
child:
TextField
(
key:
textFieldKey
,
controller:
controller
,
textDirection:
TextDirection
.
rtl
,
),
);
}
),
),
);
// The cursor is on the right of the input because it's RTL.
RenderEditable
editable
=
findRenderEditable
(
tester
);
double
cursorRight
=
editable
.
getLocalRectForCaret
(
TextPosition
(
offset:
controller
.
value
.
text
.
length
),
).
topRight
.
dx
;
double
inputWidth
=
editable
.
size
.
width
;
expect
(
inputWidth
,
narrowWidth
);
expect
(
cursorRight
,
inputWidth
-
kCaretGap
);
// After entering some text, the cursor remains on the right of the input.
await
tester
.
enterText
(
find
.
byType
(
TextField
),
'12345'
);
await
tester
.
pump
();
editable
=
findRenderEditable
(
tester
);
cursorRight
=
editable
.
getLocalRectForCaret
(
TextPosition
(
offset:
controller
.
value
.
text
.
length
),
).
topRight
.
dx
;
inputWidth
=
editable
.
size
.
width
;
expect
(
cursorRight
,
inputWidth
-
kCaretGap
);
// Since increasing the width of the input moves its right edge further to
// the right, the cursor has followed this change and still appears on the
// right of the input.
setState
(()
{
isWide
=
true
;
});
await
tester
.
pump
();
editable
=
findRenderEditable
(
tester
);
cursorRight
=
editable
.
getLocalRectForCaret
(
TextPosition
(
offset:
controller
.
value
.
text
.
length
),
).
topRight
.
dx
;
inputWidth
=
editable
.
size
.
width
;
expect
(
inputWidth
,
wideWidth
);
expect
(
cursorRight
,
inputWidth
-
kCaretGap
);
});
}
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