Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger: Run the tables keybind handler before the widgets #10074

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 43 additions & 24 deletions pcsx2-qt/Debugger/MemoryViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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)
Expand All @@ -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;
}
}
Expand All @@ -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)
Expand All @@ -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;
}
}
Expand All @@ -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;
}

/*
Expand Down Expand Up @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion pcsx2-qt/Debugger/MemoryViewWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down