Skip to content

Commit 3fa9081

Browse files
committed
fix: update reload action
1 parent 53f5aad commit 3fa9081

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/actions/ContinuePluginActions.kt

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,32 @@ class ReloadBrowserAction: ContinueToolbarAction() {
9595
override fun toolbarActionPerformed(project: Project) {
9696
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("Continue")
9797
?: return
98-
val contentManager = toolWindow.contentManager
9998
val browserService = project.service<ContinueBrowserService>()
100-
browserService.reload()
10199

102-
val newBrowser = project.getBrowser() ?: return
103-
val newBrowserComponent = newBrowser.getComponent()
104-
105-
contentManager.removeAllContents(true)
106-
val newContent = contentManager.factory.createContent(
107-
newBrowserComponent,
108-
null,
109-
false
110-
)
111-
112-
contentManager.addContent(newContent)
113-
114-
contentManager.setSelectedContent(newContent)
115-
116-
toolWindow.activate(null)
100+
// Perform the reload and UI update on the Event Dispatch Thread
101+
ApplicationManager.getApplication().invokeLater {
102+
// Reload the browser service to get a new browser instance
103+
browserService.reload()
104+
105+
val newBrowser = project.getBrowser() ?: return@invokeLater
106+
val newBrowserComponent = newBrowser.getComponent()
107+
108+
val contentManager = toolWindow.contentManager
109+
contentManager.removeAllContents(true)
110+
111+
val newContent = contentManager.factory.createContent(
112+
newBrowserComponent,
113+
null,
114+
false
115+
)
116+
contentManager.addContent(newContent)
117+
contentManager.setSelectedContent(newContent, true) // Request focus
118+
119+
toolWindow.activate({
120+
// After activation, ensure the browser's input field gets focus
121+
newBrowser.focusOnInput()
122+
}, true)
123+
}
117124
}
118125
}
119126

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/browser/ContinueBrowserService.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@ class ContinueBrowserService(val project: Project): Disposable {
4040
* This method is intended for use when browser is frozen (unresponsive).
4141
*/
4242
fun reload() {
43-
browser?.let {
44-
Disposer.dispose(it)
45-
}
43+
// Store the old browser instance to be disposed later
44+
val oldBrowser = browser
4645
browser = null
4746

47+
// Dispose the old browser after the new one is loaded and UI is updated.
48+
// This avoids race conditions. We can do this on a background thread.
49+
oldBrowser?.let {
50+
ApplicationManager.getApplication().invokeLater {
51+
Disposer.dispose(it)
52+
}
53+
}
54+
4855
load()
4956
}
5057

0 commit comments

Comments
 (0)