Files
zero/internal/tui/transcript_view.go
Alaa Elsamouly 30bff28efc Fix/detailed view scroll select (#498)
* fix(tui): strip all ANSI escapes from copied transcript text

renderAssistantMarkdownText embeds bold markers for prose and ANSI color sequences from chroma for fenced code blocks. stripMarkdownRenderControls only stripped the bold markers, leaking ANSI codes into clipboard text. Switch to ansi.Strip() to remove all escape sequences.

* refactor(tui): extract rendering dispatch and add detailed bool to transcriptBodyItems

Extract rowRenderFn and transcriptRowDispatchFn types and refactor rendering methods into *Fn variants parameterized by the render function.

Add detailed bool parameter to transcriptBodyItems to prepare for the detailed transcript viewport. All callers pass false so there is no behavior change yet.

Extract transcriptRowBodyHeightCacheKeyOpts from transcriptRowBodyHeightCacheKey so the body cap can be configured per caller.

* feat(tui): scrollable detailed transcript viewport with sidebar suppression

Enable keyboard scrolling (PgUp/PgDown/Up/Down) in detailed transcript mode by routing through scrollChat instead of swallowing the keys.

Rewrite detailedTranscriptView to use the transcriptBodyItems pipeline so the body renders through the same viewport/scroll engine as the live view.

Implement detailedTranscriptFooter with copy-status and jump-to-bottom hint integration.

Suppress the sidebar in detailed mode so the full chat width is available for reading uncapped tool output.

* test(tui): detailed transcript scroll with PgUp/Down and Up/Down arrows

TestPgUpDownScrollsDetailedTranscript verifies that PgUp scrolls toward older content and PgDown returns to the bottom in detailed mode.

TestUpDownArrowsScrollDetailedTranscript verifies that arrow keys scroll one line at a time and bottom is clamped at offset 0.

* test(tui): ANSI strip verification for markdown rendering controls and selectable text

TestStripMarkdownRenderControlsStripsAllANSI verifies bold markers, color sequences, and combined sequences are stripped.

TestSelectedTranscriptTextStripsANSIFromHighlightedCode verifies that chroma-highlighted code blocks produce clean plain text in the selectable layer.

* fix for coderabit, and better fewer code.

* fix(tui): address PR review feedback dead code, hover clear, and
rebindable key label

* format

* addressing the review issue

1. the ctrl + b in detailed mode, added the guard to not be able to do
it in detailed mode so it affect its state in the normal mode.

2. added a test coverage for keyDown after `keDown then keyUp` so it
   covers that.

* fix(tui): close file drill-in when entering detailed transcript

toggleDetailedTranscript now calls exitFileView before returning, so an active file drill-in is automatically closed when the user enters detailed transcript mode.

* test(tui): verify file drill-in closes on detailed toggle

Adds TestDetailedTranscriptClosesFileView and TestDetailedTranscriptStaysClosedOnSecondToggle to guard against the file-view bypass bug.

* fix(tui): block composer hit-test while detailed transcript is active

composerMouseSelectionBlocked and mouseOverComposer now check m.transcriptDetailed so mouse clicks and wheel events in the composer area reach the transcript body instead of being silently consumed.

* test(tui): verify composer mouse is ignored in detailed mode

Adds TestComposerMouseSelectionBlockedInDetailedMode to guard against composer hit-test swallowing mouse events during detailed transcript viewing.
2026-07-05 19:36:17 +08:00

60 lines
2.0 KiB
Go

package tui
import (
"fmt"
"strings"
)
func (m model) toggleDetailedTranscript() model {
m.transcriptDetailed = !m.transcriptDetailed
m.clearSuggestions()
if m.fileView.active {
m = m.exitFileView()
}
if m.picker != nil && m.picker.kind == pickerTheme {
// Dropping a theme picker mid-preview must undo the live palette, or the
// previewed theme would stick while m.themeMode still holds the old one.
m.restoreCommittedTheme()
}
m.picker = nil
return m
}
// detailedTranscriptView renders the full (uncapped) transcript viewport.
// Tool output that would be truncated in the live view appears in full here.
func (m model) detailedTranscriptView() string {
width := chatWidth(m.width)
items := m.transcriptBodyItems(width, "", true)
header := detailedTranscriptHeader(width) + "\n" + zeroTheme.line.Render(strings.Repeat("-", width))
footer := m.detailedTranscriptFooter(width)
if m.altScreen && m.height > 0 {
return m.scrollableTranscriptItemsView(header, items, footer, width, "")
}
// Popup/fallback: render the full body without viewport clipping.
layout := layoutTranscriptBodyItems(items)
return header + "\n" + layout.String() + "\n" + footer
}
// detailedTranscriptFooter builds the one-line footer for the detailed transcript
// view: copy status when active, otherwise the key hint with jump-to-bottom cue.
func (m model) detailedTranscriptFooter(width int) string {
if copyStatus := strings.TrimSpace(m.copyStatus); copyStatus != "" {
return rightAlignedLine(zeroTheme.ink.Render(copyStatus), width)
}
detailKey := labelOr(m.keyBindings.toggleDetailed, "Ctrl+O")
hint := zeroTheme.faint.Render(fmt.Sprintf("Esc close | %s toggle", detailKey))
if jt := m.jumpToBottomHint(); jt != "" {
return fitStyledLine(joinHeaderLine(hint, jt, width), width)
}
return fitStyledLine(hint, width)
}
func detailedTranscriptHeader(width int) string {
title := zeroTheme.ink.Bold(true).Render("Transcript")
hint := zeroTheme.faint.Render("detailed")
return fitStyledLine(joinHeaderLine(title, hint, width), width)
}