From f334e2d0f4b087652c9076c634f3599dc70bb627 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 27 May 2018 13:48:30 +0300 Subject: [PATCH] Clear formatting at the start of the field. --- Telegram/SourceFiles/ui/widgets/input_fields.cpp | 9 +++++++++ Telegram/SourceFiles/ui/widgets/input_fields.h | 1 + 2 files changed, 10 insertions(+) diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.cpp b/Telegram/SourceFiles/ui/widgets/input_fields.cpp index 7f36bc8f4..6b7717048 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -1122,6 +1122,7 @@ InputField::InputField( connect(_inner->document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(onDocumentContentsChange(int,int,int))); connect(_inner, SIGNAL(undoAvailable(bool)), this, SLOT(onUndoAvailable(bool))); connect(_inner, SIGNAL(redoAvailable(bool)), this, SLOT(onRedoAvailable(bool))); + connect(_inner, SIGNAL(cursorPositionChanged()), this, SLOT(onCursorPositionChanged())); if (App::wnd()) connect(_inner, SIGNAL(selectionChanged()), App::wnd(), SLOT(updateGlobalMenu())); const auto bar = _inner->verticalScrollBar(); @@ -1979,6 +1980,14 @@ void InputField::onDocumentContentsChange( } } +void InputField::onCursorPositionChanged() { + auto cursor = textCursor(); + if (!cursor.hasSelection() && !cursor.position()) { + cursor.setCharFormat(_defaultCharFormat); + setTextCursor(cursor); + } +} + void InputField::chopByMaxLength(int insertPosition, int insertLength) { Expects(_correcting); diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.h b/Telegram/SourceFiles/ui/widgets/input_fields.h index 4fedddc76..92bfbe1c6 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.h +++ b/Telegram/SourceFiles/ui/widgets/input_fields.h @@ -289,6 +289,7 @@ private slots: void onTouchTimer(); void onDocumentContentsChange(int position, int charsRemoved, int charsAdded); + void onCursorPositionChanged(); void onUndoAvailable(bool avail); void onRedoAvailable(bool avail);