mirror of
https://github.com/openharmony/ace_ace_engine.git
synced 2026-07-19 14:43:36 -04:00
!2165 BugFix: 修复TextInput组件插入字符时光标后移的BUG
Merge pull request !2165 from bixuefeng/bugfix_textinput_0407
This commit is contained in:
@@ -28,10 +28,12 @@ public:
|
||||
void SetText(const std::string& newText, bool needFireChangeEvent = true)
|
||||
{
|
||||
auto value = GetValue();
|
||||
value.text = newText;
|
||||
// Default set selection to the end of text is more consistent with the intuition of user.
|
||||
value.selection.Update(value.GetWideText().length());
|
||||
SetValue(std::move(value), needFireChangeEvent);
|
||||
if (value.text != newText) {
|
||||
value.text = newText;
|
||||
// Default set selection to the end of text is more consistent with the intuition of user.
|
||||
value.selection.Update(static_cast<int32_t>(value.GetWideText().length()));
|
||||
SetValue(std::move(value), needFireChangeEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void SetHint(const std::string& hint)
|
||||
|
||||
@@ -350,9 +350,6 @@ void RenderTextField::PerformLayout()
|
||||
}
|
||||
if (needNotifyChangeEvent_ && (onTextChangeEvent_ || onValueChangeEvent_ || onChange_)) {
|
||||
needNotifyChangeEvent_ = false;
|
||||
if (onChange_) {
|
||||
onChange_(GetEditingValue().text);
|
||||
}
|
||||
if (onValueChangeEvent_) {
|
||||
onValueChangeEvent_(GetEditingValue().text);
|
||||
}
|
||||
@@ -1119,6 +1116,9 @@ void RenderTextField::UpdateEditingValue(const std::shared_ptr<TextEditingValue>
|
||||
if (onValueChange_) {
|
||||
onValueChange_();
|
||||
}
|
||||
if (onChange_) {
|
||||
onChange_(GetEditingValue().text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1213,26 +1213,28 @@ bool RenderTextField::OnKeyEvent(const KeyEvent& event)
|
||||
|
||||
if (event.action == KeyAction::DOWN) {
|
||||
cursorPositionType_ = CursorPositionType::NONE;
|
||||
bool moved = true;
|
||||
if (event.code == KeyCode::TV_CONTROL_LEFT) {
|
||||
CursorMoveLeft();
|
||||
} else if (event.code == KeyCode::TV_CONTROL_RIGHT) {
|
||||
CursorMoveRight();
|
||||
} else if (event.code == KeyCode::TV_CONTROL_UP) {
|
||||
CursorMoveUp();
|
||||
} else if (event.code == KeyCode::TV_CONTROL_DOWN) {
|
||||
CursorMoveDown();
|
||||
} else {
|
||||
moved = HandleKeyEvent(event);
|
||||
}
|
||||
if (moved) {
|
||||
// Obscure all glyphs immediately after cursor moved.
|
||||
obscureTickPendings_ = 0;
|
||||
return true;
|
||||
}
|
||||
if (event.code == KeyCode::TV_CONTROL_RIGHT) {
|
||||
CursorMoveRight();
|
||||
obscureTickPendings_ = 0;
|
||||
return true;
|
||||
}
|
||||
if (event.code == KeyCode::TV_CONTROL_UP) {
|
||||
CursorMoveUp();
|
||||
obscureTickPendings_ = 0;
|
||||
return true;
|
||||
}
|
||||
if (event.code == KeyCode::TV_CONTROL_DOWN) {
|
||||
CursorMoveDown();
|
||||
obscureTickPendings_ = 0;
|
||||
return true;
|
||||
}
|
||||
return moved;
|
||||
}
|
||||
|
||||
return false;
|
||||
return HandleKeyEvent(event);
|
||||
}
|
||||
|
||||
void RenderTextField::UpdateFocusStyles()
|
||||
@@ -1780,11 +1782,11 @@ bool RenderTextField::HandleKeyEvent(const KeyEvent& event)
|
||||
if (appendElement.empty()) {
|
||||
return false;
|
||||
}
|
||||
auto value = GetEditingValue();
|
||||
value.text = value.GetBeforeSelection() + appendElement + value.GetAfterSelection();
|
||||
value.UpdateSelection(
|
||||
auto editingValue = std::make_shared<TextEditingValue>();
|
||||
editingValue->text = GetEditingValue().GetBeforeSelection() + appendElement + GetEditingValue().GetAfterSelection();
|
||||
editingValue->UpdateSelection(
|
||||
std::max(GetEditingValue().selection.GetEnd(), 0) + StringUtils::Str8ToStr16(appendElement).length());
|
||||
SetEditingValue(std::move(value));
|
||||
UpdateEditingValue(editingValue);
|
||||
MarkNeedLayout();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -184,6 +184,10 @@ void TextFieldElement::OnFocus()
|
||||
if (!enabled_) {
|
||||
return;
|
||||
}
|
||||
auto textField = DynamicCast<RenderTextField>(renderNode_);
|
||||
if (textField) {
|
||||
textField->StartTwinkling();
|
||||
}
|
||||
FocusNode::OnFocus();
|
||||
renderNode_->ChangeStatus(RenderStatus::FOCUS);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include "base/geometry/offset.h"
|
||||
#include "base/memory/ace_type.h"
|
||||
#include "core/components/scroll/scroll_fade_painter.h"
|
||||
#include "core/event/ace_events.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
|
||||
Reference in New Issue
Block a user