xonecas.io
62159
Sy

symb / commit 90adcd8

fix: clicing on a read tool moves the cursor to read start

xonecas2026-02-14 90adcd89f41b5f457255e37785257f7c37cc13e8 parent 1ec22de

3 files changed

internal/tui/mouse.go+3−0
@@ -282,6 +282,9 @@ func (m *Model) handleConvClick(wrappedLine int) tea.Cmd {
282282 m.editor.SetGutterMarkers(GitFileMarkers(m.ctx, entry.filePath))
283283 m.editor.DiagnosticLines = nil
284284 m.editorFilePath = absPath
285+ if entry.line > 0 {
286+ m.editor.GotoLine(entry.line)
287+ }
285288 m.setFocus(focusEditor)
286289 return nil
287290 }
internal/tui/tui.go+4−0
@@ -120,11 +120,15 @@ type convEntry struct {
120120 kind entryKind // Entry type
121121 filePath string // Source file path (for tool results that reference a file)
122122 full string // Fallback raw content (when no file path, e.g. Grep results)
123+ line int // Target line (1-indexed) for cursor positioning on click (0 = none)
123124 }
124125
125126 // toolResultFileRe extracts the file path from "Read path ..." / "Edited path ..." / "Created path ..." headers.
126127 var toolResultFileRe = regexp.MustCompile(`^(?:Read|Edited|Created)\s+(\S+)`)
127128
129+// toolResultLineRe extracts the start line from "(lines N-M)" in tool result headers.
130+var toolResultLineRe = regexp.MustCompile(`\(lines\s+(\d+)-\d+\)`)
131+
128132 // filePathRe matches file references like "path/to/file.go:123" or just "path/to/file.go".
129133 // Requires a '/' to avoid matching version numbers like "v1.0".
130134 var filePathRe = regexp.MustCompile(`(?:^|[\s(])([a-zA-Z0-9_./-]*[/][a-zA-Z0-9_.-]+\.[a-zA-Z]\w*)(?::(\d+))?`)
internal/tui/update.go+10−3
@@ -4,6 +4,7 @@ import (
44 "encoding/json"
55 "fmt"
66 "sort"
7+ "strconv"
78 "strings"
89 "time"
910
@@ -319,6 +320,12 @@ func (m *Model) applyToolResultMsg(msg llmToolResultMsg) {
319320 filePath = sm[1]
320321 }
321322
323+ // Extract start line from "(lines N-M)" for cursor positioning.
324+ var startLine int
325+ if sm := toolResultLineRe.FindStringSubmatch(msg.content); sm != nil {
326+ startLine, _ = strconv.Atoi(sm[1])
327+ }
328+
322329 lines := strings.Split(msg.content, "\n")
323330 preview := lines
324331 truncated := false
@@ -333,14 +340,14 @@ func (m *Model) applyToolResultMsg(msg llmToolResultMsg) {
333340 display := m.styles.Dim.Render(line)
334341 if i == 0 {
335342 display = arrow + display
336- wasBottom = m.appendConv(convEntry{display: display, kind: entryToolResult, filePath: filePath, full: msg.content})
343+ wasBottom = m.appendConv(convEntry{display: display, kind: entryToolResult, filePath: filePath, full: msg.content, line: startLine})
337344 } else {
338- m.appendConv(convEntry{display: display, kind: entryToolResult, filePath: filePath, full: msg.content})
345+ m.appendConv(convEntry{display: display, kind: entryToolResult, filePath: filePath, full: msg.content, line: startLine})
339346 }
340347 }
341348 if truncated {
342349 hint := fmt.Sprintf(" ... %d more lines (click to view)", len(lines)-maxPreviewLines)
343- m.appendConv(convEntry{display: m.styles.Muted.Render(hint), kind: entryToolResult, filePath: filePath, full: msg.content})
350+ m.appendConv(convEntry{display: m.styles.Muted.Render(hint), kind: entryToolResult, filePath: filePath, full: msg.content, line: startLine})
344351 }
345352 if wasBottom {
346353 m.scrollOffset = 0