diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d22323c..da2d00a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ - Bugfix: Fixed popups and the overlay not being draggable on Wayland. (#6573) - Bugfix: Fixed middle-clicking usernames in a local channel opening an invalid viewercard. (#6577) - Bugfix: Added `desktop-entry` hint to Linux notifications. (#6615) +- Bugfix: Fixed CMD + DELETE behavior in the user notes editing dialog for macOS. (#6676) - Dev: Update release documentation. (#6498) - Dev: Make code sanitizers opt in with the `CHATTERINO_SANITIZER_SUPPORT` CMake option. After that's enabled, use the `SANITIZE_*` flag to enable individual sanitizers. (#6493) - Dev: Remove unused QTextCodec includes. (#6487) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 93f3e6af..a643ef1c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -732,6 +732,8 @@ set(SOURCE_FILES widgets/helper/ChannelView.cpp widgets/helper/ChannelView.hpp + widgets/helper/CmdDeleteKeyFilter.cpp + widgets/helper/CmdDeleteKeyFilter.hpp widgets/helper/ComboBoxItemDelegate.cpp widgets/helper/ComboBoxItemDelegate.hpp widgets/helper/DebugPopup.cpp diff --git a/src/widgets/dialogs/EditUserNotesDialog.cpp b/src/widgets/dialogs/EditUserNotesDialog.cpp index bcbab065..3ce9c9b9 100644 --- a/src/widgets/dialogs/EditUserNotesDialog.cpp +++ b/src/widgets/dialogs/EditUserNotesDialog.cpp @@ -3,6 +3,7 @@ #include "singletons/Theme.hpp" #include "util/LayoutCreator.hpp" #include "widgets/buttons/SvgButton.hpp" +#include "widgets/helper/CmdDeleteKeyFilter.hpp" #include "widgets/MarkdownLabel.hpp" #include @@ -299,6 +300,9 @@ EditUserNotesDialog::EditUserNotesDialog(QWidget *parent) this->splitter_->setSizes({350, 350}); this->previewLabel_->setVisible(false); + auto *shortcutFilter = new CmdDeleteKeyFilter(edit.getElement()); + edit->installEventFilter(shortcutFilter); + layout .emplace(QDialogButtonBox::Ok | QDialogButtonBox::Cancel) diff --git a/src/widgets/helper/CmdDeleteKeyFilter.cpp b/src/widgets/helper/CmdDeleteKeyFilter.cpp new file mode 100644 index 00000000..f9ed5ebc --- /dev/null +++ b/src/widgets/helper/CmdDeleteKeyFilter.cpp @@ -0,0 +1,46 @@ +#include "widgets/helper/CmdDeleteKeyFilter.hpp" + +#include +#include +#include + +CmdDeleteKeyFilter::CmdDeleteKeyFilter(QObject *parent) + : QObject(parent) +{ +} + +bool CmdDeleteKeyFilter::eventFilter(QObject *obj, QEvent *event) +{ +#ifdef Q_OS_MACOS + if (event->type() != QEvent::KeyPress) + { + return false; + } + + auto *textEdit = qobject_cast(obj); + const auto *keyEvent = dynamic_cast(event); + + if (!textEdit || !keyEvent) + { + return false; + } + + if (keyEvent->modifiers() == Qt::ControlModifier && + keyEvent->key() == Qt::Key_Backspace) + { + QTextCursor cursor = textEdit->textCursor(); + + if (!cursor.hasSelection()) + { + cursor.movePosition(QTextCursor::StartOfLine, + QTextCursor::KeepAnchor); + } + + cursor.removeSelectedText(); + textEdit->setTextCursor(cursor); + + return true; + } +#endif + return false; +} diff --git a/src/widgets/helper/CmdDeleteKeyFilter.hpp b/src/widgets/helper/CmdDeleteKeyFilter.hpp new file mode 100644 index 00000000..802a17fc --- /dev/null +++ b/src/widgets/helper/CmdDeleteKeyFilter.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include + +/// CmdDeleteKeyFilter is an event filter for QTextEdit objects +/// to handle the behavior of the Command + Delete shortcut on macOS +class CmdDeleteKeyFilter : public QObject +{ + Q_OBJECT +public: + explicit CmdDeleteKeyFilter(QObject *parent = nullptr); + +protected: + bool eventFilter(QObject *obj, QEvent *event) override; +}; diff --git a/src/widgets/helper/ResizingTextEdit.cpp b/src/widgets/helper/ResizingTextEdit.cpp index 3e5361c1..b9148217 100644 --- a/src/widgets/helper/ResizingTextEdit.cpp +++ b/src/widgets/helper/ResizingTextEdit.cpp @@ -131,22 +131,6 @@ bool ResizingTextEdit::eventFilter(QObject *obj, QEvent *event) } void ResizingTextEdit::keyPressEvent(QKeyEvent *event) { -#ifdef Q_OS_MACOS - if ((event->modifiers() == Qt::ControlModifier) && - (event->key() == Qt::Key_Backspace)) - { - QTextCursor cursor = this->textCursor(); - if (!cursor.hasSelection()) - { - cursor.movePosition(QTextCursor::StartOfLine, - QTextCursor::KeepAnchor); - } - cursor.removeSelectedText(); - this->setTextCursor(cursor); - return; - } -#endif - event->ignore(); this->keyPressed.invoke(event); diff --git a/src/widgets/splits/SplitInput.cpp b/src/widgets/splits/SplitInput.cpp index 1c31131c..5de2b47a 100644 --- a/src/widgets/splits/SplitInput.cpp +++ b/src/widgets/splits/SplitInput.cpp @@ -19,6 +19,7 @@ #include "widgets/buttons/SvgButton.hpp" #include "widgets/dialogs/EmotePopup.hpp" #include "widgets/helper/ChannelView.hpp" +#include "widgets/helper/CmdDeleteKeyFilter.hpp" #include "widgets/helper/MessageView.hpp" #include "widgets/helper/ResizingTextEdit.hpp" #include "widgets/Notebook.hpp" @@ -164,6 +165,9 @@ void SplitInput::initLayout() &SplitInput::editTextChanged); textEdit->setFrameStyle(QFrame::NoFrame); + auto *shortcutFilter = new CmdDeleteKeyFilter(this); + textEdit->installEventFilter(shortcutFilter); + hboxLayout.emplace("SEND").assign(&this->ui_.sendButton); this->ui_.sendButton->hide();