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

fix editable ios bug when typing #380

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions Runtime/rendering/editable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));

Expand Down