Skip to content

Commit 168d8b6

Browse files
cpcloudcursoragent
andcommitted
feat(ui): make SQL toggle retroactive for entire session
The SQL toggle (`ctrl+s`) now shows/hides SQL for all queries in the current session, not just future queries. Changes: - Always store SQL in message history (regardless of ShowSQL state) - Filter SQL messages during rendering based on current ShowSQL value - Refresh viewport immediately when toggling so change is visible Now when you toggle SQL on, all previously executed queries in the session will show their SQL. Toggle it off and they all hide again. Closes #163 Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent d4ddd57 commit 168d8b6

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

internal/app/chat.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,12 +710,11 @@ func (m *Model) handleSQLResult(msg sqlResultMsg) tea.Cmd {
710710
return m.startFallbackStream(msg.Question)
711711
}
712712

713-
// Show the generated SQL if the user has opted in via /sql.
714-
if m.chat.ShowSQL {
715-
m.chat.Messages = append(m.chat.Messages, chatMessage{
716-
Role: "sql", Content: msg.SQL,
717-
})
718-
}
713+
// Always store the SQL in the message history so we can retroactively
714+
// show/hide it when the user toggles SQL display.
715+
m.chat.Messages = append(m.chat.Messages, chatMessage{
716+
Role: "sql", Content: msg.SQL,
717+
})
719718

720719
// Stage 2: summarize results via streaming LLM call.
721720
resultsTable := llm.FormatResultsTable(msg.Columns, msg.Rows)
@@ -824,6 +823,8 @@ func (m *Model) toggleSQL() {
824823
return
825824
}
826825
m.chat.ShowSQL = !m.chat.ShowSQL
826+
// Refresh viewport to immediately show/hide SQL for all messages.
827+
m.refreshChatViewport()
827828
}
828829

829830
// sqlHintItem renders the ctrl+s hint with color indicating whether SQL
@@ -993,6 +994,10 @@ func (m *Model) renderChatMessages() string {
993994
rendered += "\n" + lipgloss.NewStyle().Foreground(textDim).Render(sep)
994995
}
995996
case "sql":
997+
// Only render SQL messages when ShowSQL is true.
998+
if !m.chat.ShowSQL {
999+
continue
1000+
}
9961001
// Leave room for glamour's code block padding/border.
9971002
sqlWidth := innerW - 8
9981003
if sqlWidth < 30 {

0 commit comments

Comments
 (0)