diff --git a/src/duckstation-qt/debuggerwindow.cpp b/src/duckstation-qt/debuggerwindow.cpp index f0b8e1bc0..483daee80 100644 --- a/src/duckstation-qt/debuggerwindow.cpp +++ b/src/duckstation-qt/debuggerwindow.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -81,15 +82,15 @@ void DebuggerWindow::refreshAll() m_ui.memoryView->forceRefresh(); m_code_model->setPC(CPU::g_state.pc); - scrollToPC(); + scrollToPC(false); } -void DebuggerWindow::scrollToPC() +void DebuggerWindow::scrollToPC(bool center) { - return scrollToCodeAddress(CPU::g_state.pc); + return scrollToCodeAddress(CPU::g_state.pc, center); } -void DebuggerWindow::scrollToCodeAddress(VirtualMemoryAddress address) +void DebuggerWindow::scrollToCodeAddress(VirtualMemoryAddress address, bool center) { m_code_model->ensureAddressVisible(address); @@ -99,7 +100,14 @@ void DebuggerWindow::scrollToCodeAddress(VirtualMemoryAddress address) qApp->processEvents(QEventLoop::ExcludeUserInputEvents); const QModelIndex index = m_code_model->index(row, 0); - m_ui.codeView->scrollTo(index, QAbstractItemView::PositionAtCenter); + const QRect rect = m_ui.codeView->visualRect(index); + if (rect.left() < 0 || rect.top() < 0 || rect.right() > m_ui.codeView->viewport()->width() || + rect.bottom() > m_ui.codeView->viewport()->height()) + { + center = true; + } + + m_ui.codeView->scrollTo(index, center ? QAbstractItemView::PositionAtCenter : QAbstractItemView::EnsureVisible); m_ui.codeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); } @@ -131,7 +139,7 @@ void DebuggerWindow::onRunToCursorTriggered() void DebuggerWindow::onGoToPCTriggered() { - scrollToPC(); + scrollToPC(true); } void DebuggerWindow::onGoToAddressTriggered() @@ -141,7 +149,7 @@ void DebuggerWindow::onGoToAddressTriggered() if (!address.has_value()) return; - scrollToCodeAddress(address.value()); + scrollToCodeAddress(address.value(), true); } void DebuggerWindow::onDumpAddressTriggered() diff --git a/src/duckstation-qt/debuggerwindow.h b/src/duckstation-qt/debuggerwindow.h index 316f1eb16..4c5604b69 100644 --- a/src/duckstation-qt/debuggerwindow.h +++ b/src/duckstation-qt/debuggerwindow.h @@ -45,8 +45,6 @@ private Q_SLOTS: void timerRefresh(); void refreshAll(); - void scrollToPC(); - void onPauseActionToggled(bool paused); void onRunToCursorTriggered(); void onGoToPCTriggered(); @@ -78,7 +76,8 @@ private: void clearBreakpoints(); std::optional getSelectedCodeAddress(); bool tryFollowLoadStore(VirtualMemoryAddress address); - void scrollToCodeAddress(VirtualMemoryAddress address); + void scrollToPC(bool center); + void scrollToCodeAddress(VirtualMemoryAddress address, bool center); bool scrollToMemoryAddress(VirtualMemoryAddress address); void refreshBreakpointList(); void refreshBreakpointList(const CPU::BreakpointList& bps);