Skip to content

Commit 09fa598

Browse files
feat(ai-dock): sync workspace on input focus
- Workspace sync was only triggered on dock visibility change, missing the case where a user clicks into an already-visible dock's input field or sends a message - Extract sync logic into a reusable lambda to avoid duplication across the two new connection sites - Wire inputFocused through AcpSessionView → AiAgentDock → MainWindow so the signal travels the existing ownership chain without coupling the view to workspace concerns
1 parent 3fd6177 commit 09fa598

5 files changed

Lines changed: 30 additions & 14 deletions

File tree

‎src/dialogs/MainWindow.cpp‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,25 +3330,30 @@ void MainWindow::attachAiAgentDock(AiAgentDock *dock)
33303330
}
33313331
}
33323332

3333-
connect(dock, &QDockWidget::visibilityChanged, this, [this, dock](bool visible) {
3333+
auto syncWorkspaceForDock = [this, dock]() {
3334+
if (!isVisible() || !app->getSettings()->syncWorkspaceOnAiSwitch())
3335+
return;
3336+
const QString aiCwd = QDir::cleanPath(dock->workingDirectory());
3337+
if (aiCwd.isEmpty())
3338+
return;
3339+
for (auto *ws : findChildren<FolderAsWorkspaceDock *>()) {
3340+
if (QDir::cleanPath(ws->rootPath()) == aiCwd) {
3341+
ws->setVisible(true);
3342+
ws->raise();
3343+
break;
3344+
}
3345+
}
3346+
};
3347+
3348+
connect(dock, &QDockWidget::visibilityChanged, this, [this, dock, syncWorkspaceForDock](bool visible) {
33343349
if (visible) {
33353350
m_activeAiDock = dock;
3336-
3337-
if (isVisible() && app->getSettings()->syncWorkspaceOnAiSwitch()) {
3338-
const QString aiCwd = QDir::cleanPath(dock->workingDirectory());
3339-
if (!aiCwd.isEmpty()) {
3340-
for (auto *ws : findChildren<FolderAsWorkspaceDock *>()) {
3341-
if (QDir::cleanPath(ws->rootPath()) == aiCwd) {
3342-
ws->setVisible(true);
3343-
ws->raise();
3344-
break;
3345-
}
3346-
}
3347-
}
3348-
}
3351+
syncWorkspaceForDock();
33493352
}
33503353
});
33513354

3355+
connect(dock, &AiAgentDock::inputFocused, this, syncWorkspaceForDock);
3356+
33523357
addDockWidget(AiAgentDock::defaultArea(), dock);
33533358
if (existing) {
33543359
tabifyDockWidget(existing, dock);

‎src/docks/AiAgentDock.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ void AiAgentDock::wireConnectionSignals()
9292
m_goalAgent->stop();
9393
}
9494
}, Qt::UniqueConnection);
95+
connect(m_view, &AcpSessionView::inputFocused,
96+
this, &AiAgentDock::inputFocused,
97+
Qt::UniqueConnection);
9598
}
9699
}
97100

@@ -379,4 +382,5 @@ void AiAgentDock::sendWithGoal()
379382
for (const auto &p : composerImages) imageList.append(p);
380383
m_model->appendUserMessage(composerText, composerImages);
381384
m_connection->sendPrompt(composerText, imageList);
385+
emit inputFocused();
382386
}

‎src/docks/AiAgentDock.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class AiAgentDock : public QDockWidget
8585
// Carries the CURRENT (about-to-be-replaced) session id so the manager
8686
// can clean up history etc. Connected by AcpAgentManager.
8787
void restartRequested(const QString &oldSessionId);
88+
void inputFocused();
8889

8990
protected:
9091
void closeEvent(QCloseEvent *event) override;

‎src/widgets/AcpSessionView.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ void AcpSessionView::buildUi()
477477
};
478478
cb->setMaximumHeight(120);
479479
m_input = cb;
480+
m_input->installEventFilter(this);
480481
outer->addWidget(m_input);
481482

482483
// Slash-command completion popup (frameless, positioned above input).
@@ -1292,6 +1293,7 @@ void AcpSessionView::onSendClicked()
12921293

12931294
m_input->clear();
12941295
m_currentGroupCards.clear();
1296+
emit inputFocused();
12951297
// Sending is a fresh focus on the conversation — re-engage the stream
12961298
// even if the user had scrolled up earlier.
12971299
m_stickToBottom = true;
@@ -1614,6 +1616,9 @@ bool AcpSessionView::eventFilter(QObject *watched, QEvent *event)
16141616
syncTranscriptHostWidth();
16151617
positionJumpButton();
16161618
}
1619+
if (event->type() == QEvent::FocusIn && watched == m_input) {
1620+
emit inputFocused();
1621+
}
16171622
return QWidget::eventFilter(watched, event);
16181623
}
16191624

‎src/widgets/AcpSessionView.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class AcpSessionView : public QWidget
9595
void restartSessionRequested();
9696
void sendWithGoalRequested();
9797
void goalStopRequested();
98+
void inputFocused();
9899

99100
private slots:
100101
void onShowDebugLogClicked();

0 commit comments

Comments
 (0)