From f813c2de3bbb2a7e0a6803bc80f16961ae440c70 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 19 Sep 2018 21:14:01 +0300 Subject: [PATCH] Improved insertion of emotes from popup. --- src/widgets/splits/SplitInput.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/widgets/splits/SplitInput.cpp b/src/widgets/splits/SplitInput.cpp index 2f0606ae3..f56341c33 100644 --- a/src/widgets/splits/SplitInput.cpp +++ b/src/widgets/splits/SplitInput.cpp @@ -152,7 +152,18 @@ void SplitInput::openEmotePopup() this->emotePopup_ = std::make_unique(); this->emotePopup_->linkClicked.connect([this](const Link &link) { if (link.type == Link::InsertText) { - this->insertText(link.value + " "); + QTextCursor cursor = this->ui_.textEdit->textCursor(); + QString textToInsert(link.value + " "); + + auto symbolBeforeCursor = + getInputText()[cursor.position() - 1]; + // If symbol before cursor isn't space or empty + // Then insert space before emote. + if (!symbolBeforeCursor.isSpace() && + !symbolBeforeCursor.isNull()) { + textToInsert = " " + textToInsert; + } + this->insertText(textToInsert); } }); }