diff options
author | crupest <crupest@outlook.com> | 2021-11-16 22:27:03 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-11-16 22:27:03 +0800 |
commit | 17e35c8ebb51c2679421330056615fa8678b939e (patch) | |
tree | 853a45b8fa4221d791dbcff5e5b2be4831e8e28e /src/ui/controls/TextHostControlService.cpp | |
parent | ce1a7264a3325ae56e341d7af22b0fee914f213b (diff) | |
download | cru-17e35c8ebb51c2679421330056615fa8678b939e.tar.gz cru-17e35c8ebb51c2679421330056615fa8678b939e.tar.bz2 cru-17e35c8ebb51c2679421330056615fa8678b939e.zip |
...
Diffstat (limited to 'src/ui/controls/TextHostControlService.cpp')
-rw-r--r-- | src/ui/controls/TextHostControlService.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp index 3fb10a95..740fa447 100644 --- a/src/ui/controls/TextHostControlService.cpp +++ b/src/ui/controls/TextHostControlService.cpp @@ -150,6 +150,18 @@ void TextHostControlService::SetEditable(bool editable) { if (!editable) CancelComposition(); } +void TextHostControlService::SetMultiLine(bool multi_line) { + this->multi_line_ = multi_line; + + if (!multi_line) { + auto text = GetText(); + for (auto& c : text) { + if (c == u'\n') c = u' '; + } + SetText(text); + } +} + void TextHostControlService::SetText(String text, bool stop_composition) { this->text_ = std::move(text); CoerceSelection(); @@ -433,8 +445,12 @@ void TextHostControlService::GainFocusHandler( input_method_context_event_guard_ += input_method_context->CompositionEndEvent()->AddHandler(sync); input_method_context_event_guard_ += - input_method_context->TextEvent()->AddHandler( - [this](StringView text) { this->ReplaceSelectedText(text); }); + input_method_context->TextEvent()->AddHandler([this](StringView text) { + if (!multi_line_ && text == u"\n") { + return; + } + this->ReplaceSelectedText(text); + }); host::WindowHost* window_host = control_->GetWindowHost(); if (window_host) |