From 44bf1d21831c7a66f1fdca126e8b9a09e2a0036a Mon Sep 17 00:00:00 2001 From: Ty Lamontagne Date: Fri, 6 Oct 2023 11:46:21 -0400 Subject: [PATCH] Debugger: Run the tables keybind handler before the widgets This fixes the issue of 'G' executing the go-to box instead of putting it into the text view --- pcsx2-qt/Debugger/MemoryViewWidget.cpp | 67 +++++++++++++++++--------- pcsx2-qt/Debugger/MemoryViewWidget.h | 3 +- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/pcsx2-qt/Debugger/MemoryViewWidget.cpp b/pcsx2-qt/Debugger/MemoryViewWidget.cpp index 6200dceb17c13..66fbb85eab7e3 100644 --- a/pcsx2-qt/Debugger/MemoryViewWidget.cpp +++ b/pcsx2-qt/Debugger/MemoryViewWidget.cpp @@ -243,10 +243,12 @@ void MemoryViewTable::InsertAtCurrentSelection(const QString& text) { } // We need both key and keychar because `key` is easy to use, but is case insensitive -void MemoryViewTable::KeyPress(int key, QChar keychar) +bool MemoryViewTable::KeyPress(int key, QChar keychar) { if (!m_cpu->isValidAddress(selectedAddress)) - return; + return false; + + bool pressHandled = false; const bool keyCharIsText = keychar.isLetterOrNumber() || keychar.isSpace(); @@ -258,6 +260,7 @@ void MemoryViewTable::KeyPress(int key, QChar keychar) cpu->write8(address, val); QtHost::RunOnUIThread([this] { UpdateSelectedAddress(selectedAddress + 1); parent->update(); }); }); + pressHandled = true; } switch (key) @@ -268,12 +271,17 @@ void MemoryViewTable::KeyPress(int key, QChar keychar) cpu->write8(address, 0); QtHost::RunOnUIThread([this] { UpdateSelectedAddress(selectedAddress - 1); parent->update(); }); }); + pressHandled = true; break; case Qt::Key::Key_Right: UpdateSelectedAddress(selectedAddress + 1); + pressHandled = true; break; case Qt::Key::Key_Left: UpdateSelectedAddress(selectedAddress - 1); + pressHandled = true; + break; + default: break; } } @@ -283,10 +291,13 @@ void MemoryViewTable::KeyPress(int key, QChar keychar) if (keyCharIsText) { - InsertIntoSelectedHexView(((u8)QString(QChar(key)).toInt(nullptr, 16))); - // Increment to the next nibble or byte - if ((selectedNibbleHI = !selectedNibbleHI)) - UpdateSelectedAddress(selectedAddress + 1); + InsertIntoSelectedHexView(((u8)QString(QChar(key)).toInt(&pressHandled, 16))); + if (pressHandled) + { + // Increment to the next nibble or byte + if ((selectedNibbleHI = !selectedNibbleHI)) + UpdateSelectedAddress(selectedAddress + 1); + } } switch (key) @@ -297,14 +308,19 @@ void MemoryViewTable::KeyPress(int key, QChar keychar) // Move back a byte or nibble if it's backspace being pressed if (!(selectedNibbleHI = !selectedNibbleHI)) UpdateSelectedAddress(selectedAddress - 1); + pressHandled = true; break; case Qt::Key::Key_Right: if ((selectedNibbleHI = !selectedNibbleHI)) UpdateSelectedAddress(selectedAddress + 1); + pressHandled = true; break; case Qt::Key::Key_Left: if (!(selectedNibbleHI = !selectedNibbleHI)) UpdateSelectedAddress(selectedAddress - 1); + pressHandled = true; + break; + default: break; } } @@ -315,17 +331,25 @@ void MemoryViewTable::KeyPress(int key, QChar keychar) { case Qt::Key::Key_Up: UpdateSelectedAddress(selectedAddress - 0x10); + pressHandled = true; break; case Qt::Key::Key_PageUp: UpdateSelectedAddress(selectedAddress - (0x10 * rowVisible), true); + pressHandled = true; break; case Qt::Key::Key_Down: UpdateSelectedAddress(selectedAddress + 0x10); + pressHandled = true; break; case Qt::Key::Key_PageDown: UpdateSelectedAddress(selectedAddress + (0x10 * rowVisible), true); + pressHandled = true; + break; + default: break; } + + return pressHandled; } /* @@ -501,26 +525,21 @@ void MemoryViewWidget::wheelEvent(QWheelEvent* event) void MemoryViewWidget::keyPressEvent(QKeyEvent* event) { - bool handledByWidget = true; - switch (event->key()) + if (!m_table.KeyPress(event->key(), event->text().size() ? event->text()[0] : '\0')) { - case Qt::Key_G: - contextGoToAddress(); - break; - case Qt::Key_C: - if (event->modifiers() & Qt::ControlModifier) - contextCopySegment(); - else - handledByWidget = false; - break; - default: - handledByWidget = false; - break; + switch (event->key()) + { + case Qt::Key_G: + contextGoToAddress(); + break; + case Qt::Key_C: + if (event->modifiers() & Qt::ControlModifier) + contextCopySegment(); + break; + default: + break; + } } - - if (!handledByWidget) - m_table.KeyPress(event->key(), event->text().size() ? event->text()[0] : '\0'); - this->repaint(); VMUpdate(); } diff --git a/pcsx2-qt/Debugger/MemoryViewWidget.h b/pcsx2-qt/Debugger/MemoryViewWidget.h index eb55f64e333cf..8ff7589de64f6 100644 --- a/pcsx2-qt/Debugger/MemoryViewWidget.h +++ b/pcsx2-qt/Debugger/MemoryViewWidget.h @@ -72,7 +72,8 @@ class MemoryViewTable void SelectAt(QPoint pos); u128 GetSelectedSegment(); void InsertAtCurrentSelection(const QString& text); - void KeyPress(int key, QChar keychar); + // Returns true if the keypress was handled + bool KeyPress(int key, QChar keychar); MemoryViewType GetViewType() {