From d92889b37ed17d63f4db6be571f9254391186e83 Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Mon, 18 Jun 2018 19:59:05 -0500 Subject: [PATCH] client: Fix text format shortcuts edge case When toggling text formatting via keyboard shortcuts, always update the button state, too. This fixes an issue where in certain situations formatting could not be removed by shortcut, only by button. (I originally avoided doing this out of concern it'd create a loop with the clicked() signal firing when setting check state. Thankfully that's not the case.) Test case: 1. Type "test message here" 2. Select "message", mark as italic (button or shortcut) 3. Move cursor to end of message, so italic button becomes unpressed 4. Click at the end of the word "message" (after the 'e'), and drag-select/Shift-Arrow select up to the beginning of the message (before the 'm'). 5. Use shortcut to toggle italic, several times 6. Use button to toggle italic, several times > Before The italic shortcut would not toggle on then off, clearing the format > After The italic shortcut works after toggling twice, just like the button. Having to toggle twice in this situation is a bug that existed before the formatting shortcut changes. --- src/qtui/inputwidget.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/qtui/inputwidget.cpp b/src/qtui/inputwidget.cpp index 8d84233d..48d9bc6c 100644 --- a/src/qtui/inputwidget.cpp +++ b/src/qtui/inputwidget.cpp @@ -554,16 +554,16 @@ void InputWidget::changeNick(const QString &newNick) const void InputWidget::onTextEntered(const QString &text) { Client::userInput(currentBufferInfo(), text); - ui.boldButton->setChecked(false); - ui.underlineButton->setChecked(false); - ui.italicButton->setChecked(false); + // Remove formatting from entered text + // TODO: Offer a way to convert pasted text to mIRC formatting codes setFormatClear(true); } void InputWidget::setFormatClear(const bool global) { + // Apply formatting QTextCharFormat fmt; fmt.setFontWeight(QFont::Normal); fmt.setFontUnderline(false); @@ -575,30 +575,44 @@ void InputWidget::setFormatClear(const bool global) } else { setFormatOnSelection(fmt); } + + // Make sure UI state follows + ui.boldButton->setChecked(false); + ui.italicButton->setChecked(false); + ui.underlineButton->setChecked(false); } void InputWidget::setFormatBold(const bool bold) { + // Apply formatting QTextCharFormat fmt; fmt.setFontWeight(bold ? QFont::Bold : QFont::Normal); mergeFormatOnSelection(fmt); + // Make sure UI state follows + ui.boldButton->setChecked(bold); } void InputWidget::setFormatItalic(const bool italic) { + // Apply formatting QTextCharFormat fmt; fmt.setFontItalic(italic); mergeFormatOnSelection(fmt); + // Make sure UI state follows + ui.italicButton->setChecked(italic); } void InputWidget::setFormatUnderline(const bool underline) { + // Apply formatting QTextCharFormat fmt; fmt.setFontUnderline(underline); mergeFormatOnSelection(fmt); + // Make sure UI state follows + ui.underlineButton->setChecked(underline); } -- 2.20.1