fix(macOS): command + delete (#6676)

Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
Reviewed-by: Nerixyz <nerixdev@outlook.de>
This commit is contained in:
Jacob Alexander Thompson
2025-12-28 04:42:14 -08:00
committed by GitHub
parent e2ba7dff03
commit 399bacc4eb
7 changed files with 72 additions and 16 deletions
+1
View File
@@ -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 <kbd>CMD</kbd> + <kbd>DELETE</kbd> 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)
+2
View File
@@ -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
@@ -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 <QCheckBox>
@@ -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>(QDialogButtonBox::Ok |
QDialogButtonBox::Cancel)
+46
View File
@@ -0,0 +1,46 @@
#include "widgets/helper/CmdDeleteKeyFilter.hpp"
#include <QKeyEvent>
#include <QTextCursor>
#include <QTextEdit>
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<QTextEdit *>(obj);
const auto *keyEvent = dynamic_cast<QKeyEvent *>(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;
}
+15
View File
@@ -0,0 +1,15 @@
#pragma once
#include <QObject>
/// 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;
};
-16
View File
@@ -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);
+4
View File
@@ -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<LabelButton>("SEND").assign(&this->ui_.sendButton);
this->ui_.sendButton->hide();