@@ -1,15 +1,10 @@
11 package tui
22
33 import (
4- "os"
5- "path/filepath"
6- "strconv"
7- "strings"
84 "time"
95
106 tea "charm.land/bubbletea/v2"
117 "charm.land/lipgloss/v2"
12- "github.com/xonecas/symb/internal/highlight"
138 )
149
1510 // ---------------------------------------------------------------------------
@@ -46,21 +41,6 @@ func mouseXY(msg tea.MouseMsg) (int, int) {
4641 func (m Model) handleMouse(msg tea.MouseMsg) (tea.Model, tea.Cmd) {
4742 x, y := mouseXY(msg)
4843
49- // --- Divider drag -------------------------------------------------------
50- if done, handled := m.handleDividerDrag(msg, x, y); handled {
51- return done, nil
52- }
53-
54- // --- Focus switching on click -------------------------------------------
55- m.handleFocusClick(msg, x, y)
56-
57- // --- Editor: forward with original coords (left pane starts at 0) -------
58- if inRect(x, y, m.layout.editor) {
59- var cmd tea.Cmd
60- m.editor, cmd = m.editor.Update(msg)
61- return m, cmd
62- }
63-
6444 // --- Input: translate coords to component-local -------------------------
6545 if inRect(x, y, m.layout.input) {
6646 translated := m.translateMouse(msg, m.layout.input.Min.X, m.layout.input.Min.Y)
@@ -77,49 +57,6 @@ func (m Model) handleMouse(msg tea.MouseMsg) (tea.Model, tea.Cmd) {
7757 return m, nil
7858 }
7959
80-// handleDividerDrag tracks divider click/release and processes drag motion.
81-// Returns (model, true) if the event was consumed by the divider.
82-func (m *Model) handleDividerDrag(msg tea.MouseMsg, x, y int) (Model, bool) {
83- switch ev := msg.(type) {
84- case tea.MouseClickMsg:
85- if ev.Button == tea.MouseLeft && inRect(x, y, m.layout.div) {
86- m.resizingPane = true
87- }
88- case tea.MouseReleaseMsg:
89- m.resizingPane = false
90- default:
91- }
92- if m.resizingPane {
93- if _, ok := msg.(tea.MouseMotionMsg); ok {
94- if x >= minPaneWidth && x <= m.width-minPaneWidth {
95- m.divX = x
96- m.layout = generateLayout(m.width, m.height, m.divX)
97- m.updateComponentSizes()
98- }
99- return *m, true
100- }
101- }
102- return Model{}, false
103-}
104-
105-// handleFocusClick switches focus when clicking in the editor or input panes.
106-func (m *Model) handleFocusClick(msg tea.MouseMsg, x, y int) {
107- click, ok := msg.(tea.MouseClickMsg)
108- if !ok || click.Button != tea.MouseLeft {
109- return
110- }
111- switch {
112- case inRect(x, y, m.layout.editor):
113- m.setFocus(focusEditor)
114- m.agentInput.ClearSelection()
115- m.convSel = nil
116- case inRect(x, y, m.layout.input):
117- m.setFocus(focusInput)
118- m.editor.ClearSelection()
119- m.convSel = nil
120- }
121-}
122-
12360 // handleConvMouse handles mouse events within the conversation pane.
12461 func (m *Model) handleConvMouse(msg tea.MouseMsg, x, y int) tea.Cmd {
12562 lines := m.wrappedConvLines()
@@ -131,7 +68,6 @@ func (m *Model) handleConvMouse(msg tea.MouseMsg, x, y int) tea.Cmd {
13168 cp := m.convPosFromScreen(x, y, totalLines)
13269 m.convDragging = true
13370 m.convSel = &convSelection{anchor: cp, active: cp}
134- m.editor.ClearSelection()
13571 m.agentInput.ClearSelection()
13672 }
13773 case tea.MouseMotionMsg:
@@ -323,65 +259,3 @@ func (m *Model) handleToolResultView(entry convEntry) tea.Cmd {
323259 return openToolViewMsg{title: title, content: entry.full}
324260 }
325261 }
326-
327-// openFileAtCenter opens a file and positions the cursor in the middle of the
328-// read range (for Read tool results).
329-func (m *Model) openFileAtCenter(path string, startLine int, content string) tea.Cmd {
330- if sm := toolResultRangeRe.FindStringSubmatch(content); sm != nil {
331- start, _ := strconv.Atoi(sm[1])
332- end, _ := strconv.Atoi(sm[2])
333- if start > 0 && end >= start {
334- return m.openFile(path, (start+end)/2)
335- }
336- }
337- return m.openFile(path, startLine)
338-}
339-
340-// showRawContent loads raw text content into the editor for viewing.
341-func (m *Model) showRawContent(content, language string) {
342- m.editor.SetValue(content)
343- m.editor.Language = language
344- m.editor.SetGutterMarkers(nil)
345- m.editor.DiagnosticLines = nil
346- m.editorFilePath = ""
347- m.lspErrors = 0
348- m.lspWarnings = 0
349- m.setFocus(focusEditor)
350-}
351-
352-// openFile loads a file into the editor. path is relative to cwd.
353-func (m *Model) openFile(path string, lineNum int) tea.Cmd {
354- absPath, err := filepath.Abs(path)
355- if err != nil {
356- return nil
357- }
358-
359- // Restrict to files within the working directory
360- wd, err := os.Getwd()
361- if err != nil {
362- return nil
363- }
364- rel, err := filepath.Rel(wd, absPath)
365- if err != nil || strings.HasPrefix(rel, "..") {
366- return nil
367- }
368-
369- content, err := os.ReadFile(absPath)
370- if err != nil {
371- return nil
372- }
373-
374- language := highlight.DetectLanguage(path)
375- m.editor.SetValue(string(content))
376- m.editor.Language = language
377- m.editor.SetGutterMarkers(GitFileMarkers(m.ctx, path))
378- m.editor.DiagnosticLines = nil
379- m.editorFilePath = absPath
380- m.lspErrors = 0
381- m.lspWarnings = 0
382- if lineNum > 0 {
383- m.editor.GotoLine(lineNum)
384- }
385- m.setFocus(focusEditor)
386- return nil
387-}