aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-11-16 22:27:03 +0800
committercrupest <crupest@outlook.com>2021-11-16 22:27:03 +0800
commit17e35c8ebb51c2679421330056615fa8678b939e (patch)
tree853a45b8fa4221d791dbcff5e5b2be4831e8e28e /src/ui/controls
parentce1a7264a3325ae56e341d7af22b0fee914f213b (diff)
downloadcru-17e35c8ebb51c2679421330056615fa8678b939e.tar.gz
cru-17e35c8ebb51c2679421330056615fa8678b939e.tar.bz2
cru-17e35c8ebb51c2679421330056615fa8678b939e.zip
...
Diffstat (limited to 'src/ui/controls')
-rw-r--r--src/ui/controls/TextHostControlService.cpp20
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)