From dec572c672d024c8851ecd8f92702e31a41b4e78 Mon Sep 17 00:00:00 2001 From: "xingwei.zhu" Date: Tue, 19 Nov 2019 11:27:14 +0800 Subject: [PATCH] fix editable ios bug when typing --- Runtime/rendering/editable.cs | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/Runtime/rendering/editable.cs b/Runtime/rendering/editable.cs index 483e5fe0..fa406549 100644 --- a/Runtime/rendering/editable.cs +++ b/Runtime/rendering/editable.cs @@ -1320,7 +1320,7 @@ Rect _getCaretPrototype { get { switch (Application.platform) { case RuntimePlatform.IPhonePlayer: - return Rect.fromLTWH(0.0f, -EditableUtils._kCaretHeightOffset + 0.5f, this.cursorWidth, + return Rect.fromLTWH(0.0f, 0.0f, this.cursorWidth, this.preferredLineHeight + 2.0f); default: return Rect.fromLTWH(0.0f, EditableUtils._kCaretHeightOffset, this.cursorWidth, @@ -1363,17 +1363,29 @@ void _paintCaret(Canvas canvas, Offset effectiveOffset, TextPosition textPositio if (this._cursorOffset != null) { caretRect = caretRect.shift(this._cursorOffset); } - -#if !UNITY_IOS - if (this._textPainter.getFullHeightForCaret(textPosition, this._caretPrototype) != null) { - caretRect = Rect.fromLTWH( - caretRect.left, - caretRect.top - EditableUtils._kCaretHeightOffset, - caretRect.width, - this._textPainter.getFullHeightForCaret(textPosition, this._caretPrototype).Value - ); + + float? caretHeight = this._textPainter.getFullHeightForCaret(textPosition, this._caretPrototype); + if (caretHeight != null) { + switch (Application.platform) { + case RuntimePlatform.IPhonePlayer: + float heightDiff = caretHeight.Value - caretRect.height; + caretRect = Rect.fromLTWH( + caretRect.left, + caretRect.top + heightDiff / 2f, + caretRect.width, + caretRect.height + ); + break; + default: + caretRect = Rect.fromLTWH( + caretRect.left, + caretRect.top - EditableUtils._kCaretHeightOffset, + caretRect.width, + caretHeight.Value + ); + break; + } } -#endif caretRect = caretRect.shift(this._getPixelPerfectCursorOffset(caretRect));