Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 867331b

Browse files
author
Yuncong Zhang
authored
Merge pull request #380 from UnityTech/fix_editable_ios_bug
fix editable ios bug when typing
2 parents 3114029 + dec572c commit 867331b

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

Runtime/rendering/editable.cs

+23-11
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ Rect _getCaretPrototype {
13201320
get {
13211321
switch (Application.platform) {
13221322
case RuntimePlatform.IPhonePlayer:
1323-
return Rect.fromLTWH(0.0f, -EditableUtils._kCaretHeightOffset + 0.5f, this.cursorWidth,
1323+
return Rect.fromLTWH(0.0f, 0.0f, this.cursorWidth,
13241324
this.preferredLineHeight + 2.0f);
13251325
default:
13261326
return Rect.fromLTWH(0.0f, EditableUtils._kCaretHeightOffset, this.cursorWidth,
@@ -1363,17 +1363,29 @@ void _paintCaret(Canvas canvas, Offset effectiveOffset, TextPosition textPositio
13631363
if (this._cursorOffset != null) {
13641364
caretRect = caretRect.shift(this._cursorOffset);
13651365
}
1366-
1367-
#if !UNITY_IOS
1368-
if (this._textPainter.getFullHeightForCaret(textPosition, this._caretPrototype) != null) {
1369-
caretRect = Rect.fromLTWH(
1370-
caretRect.left,
1371-
caretRect.top - EditableUtils._kCaretHeightOffset,
1372-
caretRect.width,
1373-
this._textPainter.getFullHeightForCaret(textPosition, this._caretPrototype).Value
1374-
);
1366+
1367+
float? caretHeight = this._textPainter.getFullHeightForCaret(textPosition, this._caretPrototype);
1368+
if (caretHeight != null) {
1369+
switch (Application.platform) {
1370+
case RuntimePlatform.IPhonePlayer:
1371+
float heightDiff = caretHeight.Value - caretRect.height;
1372+
caretRect = Rect.fromLTWH(
1373+
caretRect.left,
1374+
caretRect.top + heightDiff / 2f,
1375+
caretRect.width,
1376+
caretRect.height
1377+
);
1378+
break;
1379+
default:
1380+
caretRect = Rect.fromLTWH(
1381+
caretRect.left,
1382+
caretRect.top - EditableUtils._kCaretHeightOffset,
1383+
caretRect.width,
1384+
caretHeight.Value
1385+
);
1386+
break;
1387+
}
13751388
}
1376-
#endif
13771389

13781390
caretRect = caretRect.shift(this._getPixelPerfectCursorOffset(caretRect));
13791391

0 commit comments

Comments
 (0)