Skip to content

Commit c324706

Browse files
authored
Merge pull request #733 from rumpl/fix-mouse-selection
Fix the mouse position on selection
2 parents d63c3cb + eb682b8 commit c324706

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

pkg/tui/components/messages/messages.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Model interface {
4141
layout.Sizeable
4242
layout.Focusable
4343
layout.Help
44+
layout.Positionable
4445

4546
AddUserMessage(content string) tea.Cmd
4647
AddErrorMessage(content string) tea.Cmd
@@ -111,6 +112,8 @@ type model struct {
111112
selection selectionState
112113

113114
splitDiffView bool
115+
116+
xPos, yPos int
114117
}
115118

116119
// New creates a new message list component
@@ -330,6 +333,12 @@ func (m *model) SetSize(width, height int) tea.Cmd {
330333
return nil
331334
}
332335

336+
func (m *model) SetPosition(x, y int) tea.Cmd {
337+
m.xPos = x
338+
m.yPos = y
339+
return nil
340+
}
341+
333342
// GetSize returns the current dimensions
334343
func (m *model) GetSize() (width, height int) {
335344
return m.width, m.height
@@ -746,12 +755,11 @@ func (m *model) removePendingToolCallMessages() {
746755

747756
// mouseToLineCol converts mouse position to line/column in rendered content
748757
func (m *model) mouseToLineCol(x, y int) (line, col int) {
749-
// Adjust for header (2 lines: text + bottom padding)
750-
adjustedY := max(0, y-2)
758+
adjustedY := max(0, y-m.yPos)
751759
line = m.scrollOffset + adjustedY
752760

753761
// Adjust for left padding (1 column from AppStyle)
754-
adjustedX := max(0, x-1)
762+
adjustedX := max(0, x-1-m.xPos)
755763
col = adjustedX
756764

757765
return line, col

pkg/tui/core/layout/layout.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ type Focusable interface {
1717
Blur() tea.Cmd
1818
}
1919

20+
type Positionable interface {
21+
SetPosition(x, y int) tea.Cmd
22+
}
23+
2024
// Help represents components that provide help information
2125
type Help interface {
2226
Bindings() []key.Binding

pkg/tui/page/chat/chat.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,13 @@ func (p *chatPage) SetSize(width, height int) tea.Cmd {
405405
mainWidth = innerWidth - sidebarWidth
406406
p.chatHeight = height - p.inputHeight
407407
p.sidebar.SetMode(sidebar.ModeVertical)
408-
cmds = append(cmds, p.sidebar.SetSize(sidebarWidth, p.chatHeight))
408+
cmds = append(cmds, p.sidebar.SetSize(sidebarWidth, p.chatHeight), p.messages.SetPosition(0, 0))
409409
} else {
410410
const horizontalSidebarHeight = 3
411411
mainWidth = innerWidth
412412
p.chatHeight = height - p.inputHeight - horizontalSidebarHeight
413413
p.sidebar.SetMode(sidebar.ModeHorizontal)
414-
cmds = append(cmds, p.sidebar.SetSize(width, horizontalSidebarHeight))
414+
cmds = append(cmds, p.sidebar.SetSize(width, horizontalSidebarHeight), p.messages.SetPosition(0, horizontalSidebarHeight))
415415
}
416416

417417
// Set component sizes

0 commit comments

Comments
 (0)