上下方向键支持跳到首行/末行

Signed-off-by: zhoukechen <zhoukechen2@huawei.com>
Change-Id: Ida4081c80ba1636354ed5d51c108dba110a4a307
This commit is contained in:
zhoukechen 2024-08-24 20:35:55 +08:00
parent c28c775198
commit 475297ca93

View File

@ -4483,11 +4483,16 @@ bool TextFieldPattern::CursorMoveEnd()
bool TextFieldPattern::CursorMoveUpOperation()
{
CHECK_NULL_RETURN(IsTextArea(), false);
if (!IsTextArea()) {
return CursorMoveToParagraphBegin();
}
auto originCaretPosition = selectController_->GetCaretIndex();
auto offsetX = selectController_->GetCaretRect().GetX();
// multiply by 0.5f to convert to the grapheme center point of the previous line.
auto offsetY = selectController_->GetCaretRect().GetY() - PreferredLineHeight() * 0.5f;
if (offsetY < textRect_.GetY()) {
return CursorMoveToParagraphBegin();
}
std::optional<Offset> offset;
offset.emplace(Offset(offsetX, offsetY));
OnCursorMoveDone(TextAffinity::DOWNSTREAM, offset);
@ -4506,11 +4511,16 @@ bool TextFieldPattern::CursorMoveUp()
bool TextFieldPattern::CursorMoveDownOperation()
{
CHECK_NULL_RETURN(IsTextArea(), false);
if (!IsTextArea()) {
return CursorMoveToParagraphEnd();
}
auto originCaretPosition = selectController_->GetCaretIndex();
auto offsetX = selectController_->GetCaretRect().GetX();
// multiply by 1.5f to convert to the grapheme center point of the next line.
auto offsetY = selectController_->GetCaretRect().GetY() + PreferredLineHeight() * 1.5f;
if (offsetY > textRect_.GetY() + textRect_.Height()) {
return CursorMoveToParagraphEnd();
}
std::optional<Offset> offset;
offset.emplace(Offset(offsetX, offsetY));
OnCursorMoveDone(TextAffinity::DOWNSTREAM, offset);