Skip to content

Commit 15b75ec

Browse files
committed
feat(gui): prevent saving session when displaying history
Add isDisplayingHistoryMessages flag to SketchToolWindow to track when historical messages are being displayed. Update NewSketchAction to skip session saving when viewing history to avoid overwriting current session data with historical content.
1 parent 9de1e15 commit 15b75ec

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/toolbar/NewSketchAction.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ class NewSketchAction : AnAction(AllIcons.General.Add), CustomComponentAction {
4343
val sketchPanel =
4444
contentManager?.component?.components?.filterIsInstance<SketchToolWindow>()?.firstOrNull()
4545

46-
saveCurrentSession(project, sketchPanel)
46+
if (sketchPanel?.isDisplayingHistoryMessages != true) {
47+
saveCurrentSession(project, sketchPanel)
48+
}
49+
4750
sketchPanel?.resetSketchSession()
4851
}
4952

5053
private fun saveCurrentSession(project: Project, sketchToolWindow: SketchToolWindow?) {
5154
if (sketchToolWindow == null) return
55+
if (sketchToolWindow.isDisplayingHistoryMessages) return
5256

5357
val agentStateService = project.getService(AgentStateService::class.java) ?: return
5458
val chatHistoryService = project.getService(ChatHistoryService::class.java) ?: return
@@ -82,7 +86,10 @@ class NewSketchAction : AnAction(AllIcons.General.Add), CustomComponentAction {
8286
if (sketchPanel == null) {
8387
return@addActionListener
8488
}
85-
saveCurrentSession(project, sketchPanel)
89+
// 只有在不是显示历史消息时才保存当前会话
90+
if (!sketchPanel.isDisplayingHistoryMessages) {
91+
saveCurrentSession(project, sketchPanel)
92+
}
8693
sketchPanel.resetSketchSession()
8794
}
8895
}

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchToolWindow.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ open class SketchToolWindow(
9494

9595
var isUserScrolling: Boolean = false
9696
protected var isInterrupted: Boolean = false
97+
var isDisplayingHistoryMessages: Boolean = false
9798

9899
protected var systemPromptPanel: JPanel = JPanel(BorderLayout())
99100
protected var contentPanel = JPanel(BorderLayout())
@@ -489,6 +490,7 @@ open class SketchToolWindow(
489490

490491
fun displayMessages(messages: List<cc.unitmesh.devti.llms.custom.Message>) {
491492
runInEdt {
493+
isDisplayingHistoryMessages = true
492494
messages.forEach { message ->
493495
val isUser = message.role.lowercase() == "user"
494496
val language = "markdown"
@@ -506,6 +508,7 @@ open class SketchToolWindow(
506508

507509
fun resetSketchSession() {
508510
runInEdt {
511+
isDisplayingHistoryMessages = false
509512
progressBar.isVisible = false
510513
blockViews.clear()
511514
systemPromptPanel.removeAll()

0 commit comments

Comments
 (0)