aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/TextHostControlService.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/controls/TextHostControlService.cpp')
-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)