void AdjustCaret(TextField.CharPosition cp)
{
_caretPosition = cp.caretIndex;
Vector2 pos = GetCharLocation(cp);
TextField.LineInfo line = textField.lines[cp.lineIndex];
pos.y = line.y + textField.y;
Vector2 newPos = pos;
if (newPos.x < textField.textFormat.size)
newPos.x += Math.Min(50, (int)(_contentRect.width / 2));
else if (newPos.x > _contentRect.width - GUTTER_X - textField.textFormat.size)
newPos.x -= Math.Min(50, (int)(_contentRect.width / 2));
if (newPos.x < GUTTER_X)
newPos.x = GUTTER_X;
else if (newPos.x > _contentRect.width - GUTTER_X)
newPos.x = Math.Max(GUTTER_X, _contentRect.width - GUTTER_X);
if (newPos.y < GUTTER_Y)
newPos.y = GUTTER_Y;
else if (newPos.y + line.height >= _contentRect.height - GUTTER_Y)
newPos.y = Math.Max(GUTTER_Y, _contentRect.height - line.height - GUTTER_Y);
pos += MoveContent(newPos - pos);
if (_editing)
{
if (line.height > 0) //将光标居中
pos.y += (int)(line.height - textField.textFormat.size) / 2;
_caret.SetPosition(pos.x, pos.y, 0);
Vector2 cursorPos = _caret.LocalToGlobal(new Vector2(0, _caret.height));
Input.compositionCursorPos = cursorPos;
_nextBlink = Time.time + 0.5f;
_caret.graphics.enabled = true;
if (_selectionStart != null)
UpdateSelection(cp);
}
}