From 9dec93315173999c4fb9ab5a0e57909eb5e7fd8b Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 26 Oct 2021 16:32:13 +0800 Subject: ... --- src/ui/controls/TextBlock.cpp | 8 +++----- src/ui/controls/TextHostControlService.cpp | 11 ++++------- 2 files changed, 7 insertions(+), 12 deletions(-) (limited to 'src/ui/controls') diff --git a/src/ui/controls/TextBlock.cpp b/src/ui/controls/TextBlock.cpp index 0724edcf..16fd5df6 100644 --- a/src/ui/controls/TextBlock.cpp +++ b/src/ui/controls/TextBlock.cpp @@ -10,7 +10,7 @@ using render::TextRenderObject; TextBlock* TextBlock::Create() { return new TextBlock(); } -TextBlock* TextBlock::Create(std::u16string text, bool selectable) { +TextBlock* TextBlock::Create(String text, bool selectable) { auto c = new TextBlock(); c->SetText(text); c->SetSelectable(selectable); @@ -38,11 +38,9 @@ render::RenderObject* TextBlock::GetRenderObject() const { return text_render_object_.get(); } -std::u16string TextBlock::GetText() const { return service_->GetText(); } +String TextBlock::GetText() const { return service_->GetText(); } -void TextBlock::SetText(std::u16string text) { - service_->SetText(std::move(text)); -} +void TextBlock::SetText(String text) { service_->SetText(std::move(text)); } bool TextBlock::IsSelectable() const { return service_->IsEnabled(); } diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp index 2f096126..2233d1e6 100644 --- a/src/ui/controls/TextHostControlService.cpp +++ b/src/ui/controls/TextHostControlService.cpp @@ -68,14 +68,13 @@ void TextHostControlService::SetText(String text, bool stop_composition) { SyncTextRenderObject(); } -void TextHostControlService::InsertText(gsl::index position, - std::u16string_view text, +void TextHostControlService::InsertText(gsl::index position, StringView text, bool stop_composition) { if (!Utf16IsValidInsertPosition(this->text_, position)) { log::TagError(log_tag, u"Invalid text insert position."); return; } - this->text_.insert(this->text_.cbegin() + position, text.begin(), text.end()); + this->text_.insert(this->text_.cbegin() + position, text); if (stop_composition) { CancelComposition(); } @@ -224,7 +223,7 @@ void TextHostControlService::AbortSelection() { SetSelection(GetCaretPosition()); } -void TextHostControlService::ReplaceSelectedText(std::u16string_view text) { +void TextHostControlService::ReplaceSelectedText(StringView text) { DeleteSelectedText(); InsertText(GetSelection().GetStart(), text); SetSelection(GetSelection().GetStart() + text.size()); @@ -344,9 +343,7 @@ void TextHostControlService::GainFocusHandler( input_method_context->CompositionEndEvent()->AddHandler(sync); input_method_context_event_guard_ += input_method_context->TextEvent()->AddHandler( - [this](const std::u16string_view& text) { - this->ReplaceSelectedText(text); - }); + [this](StringView text) { this->ReplaceSelectedText(text); }); host::WindowHost* window_host = control_->GetWindowHost(); if (window_host) -- cgit v1.2.3