mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-05-30 02:49:12 -04:00
fix: Prevent crash on cancelling quick refactor via progress widget
This commit is contained in:
@@ -385,25 +385,25 @@ void QuickRefactorHandler::handleLLMResponse(
|
||||
|
||||
void QuickRefactorHandler::cancelRequest()
|
||||
{
|
||||
if (m_isRefactoringInProgress) {
|
||||
auto id = m_lastRequestId;
|
||||
|
||||
for (auto it = m_activeRequests.begin(); it != m_activeRequests.end(); ++it) {
|
||||
if (it.key() == id) {
|
||||
const RequestContext &ctx = it.value();
|
||||
ctx.provider->cancelRequest(id);
|
||||
m_activeRequests.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!m_isRefactoringInProgress)
|
||||
return;
|
||||
|
||||
const auto id = m_lastRequestId;
|
||||
m_isRefactoringInProgress = false;
|
||||
m_lastRequestId = {};
|
||||
|
||||
auto it = m_activeRequests.find(id);
|
||||
if (it != m_activeRequests.end()) {
|
||||
auto provider = it.value().provider;
|
||||
m_activeRequests.erase(it);
|
||||
if (provider)
|
||||
provider->cancelRequest(id);
|
||||
}
|
||||
|
||||
RefactorResult result;
|
||||
result.success = false;
|
||||
result.errorMessage = "Refactoring request was cancelled";
|
||||
emit refactoringCompleted(result);
|
||||
}
|
||||
}
|
||||
|
||||
void QuickRefactorHandler::handleFullResponse(const QString &requestId, const QString &fullText)
|
||||
|
||||
@@ -142,10 +142,12 @@ void ProgressWidget::leaveEvent(QEvent *event)
|
||||
void ProgressWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton && m_isHovered) {
|
||||
event->accept();
|
||||
auto callback = m_cancelCallback;
|
||||
emit cancelRequested();
|
||||
if (m_cancelCallback) {
|
||||
m_cancelCallback();
|
||||
}
|
||||
if (callback)
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
QWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user