diff --git a/pkg/tui/components/messages/messages.go b/pkg/tui/components/messages/messages.go index bd639240a..3d3a3383c 100644 --- a/pkg/tui/components/messages/messages.go +++ b/pkg/tui/components/messages/messages.go @@ -41,6 +41,7 @@ type Model interface { layout.Sizeable layout.Focusable layout.Help + layout.Positionable AddUserMessage(content string) tea.Cmd AddErrorMessage(content string) tea.Cmd @@ -111,6 +112,8 @@ type model struct { selection selectionState splitDiffView bool + + xPos, yPos int } // New creates a new message list component @@ -330,6 +333,12 @@ func (m *model) SetSize(width, height int) tea.Cmd { return nil } +func (m *model) SetPosition(x, y int) tea.Cmd { + m.xPos = x + m.yPos = y + return nil +} + // GetSize returns the current dimensions func (m *model) GetSize() (width, height int) { return m.width, m.height @@ -746,12 +755,11 @@ func (m *model) removePendingToolCallMessages() { // mouseToLineCol converts mouse position to line/column in rendered content func (m *model) mouseToLineCol(x, y int) (line, col int) { - // Adjust for header (2 lines: text + bottom padding) - adjustedY := max(0, y-2) + adjustedY := max(0, y-m.yPos) line = m.scrollOffset + adjustedY // Adjust for left padding (1 column from AppStyle) - adjustedX := max(0, x-1) + adjustedX := max(0, x-1-m.xPos) col = adjustedX return line, col diff --git a/pkg/tui/core/layout/layout.go b/pkg/tui/core/layout/layout.go index dcb909a81..f4137a8df 100644 --- a/pkg/tui/core/layout/layout.go +++ b/pkg/tui/core/layout/layout.go @@ -17,6 +17,10 @@ type Focusable interface { Blur() tea.Cmd } +type Positionable interface { + SetPosition(x, y int) tea.Cmd +} + // Help represents components that provide help information type Help interface { Bindings() []key.Binding diff --git a/pkg/tui/page/chat/chat.go b/pkg/tui/page/chat/chat.go index bdbbe1507..0b3a9ffad 100644 --- a/pkg/tui/page/chat/chat.go +++ b/pkg/tui/page/chat/chat.go @@ -405,13 +405,13 @@ func (p *chatPage) SetSize(width, height int) tea.Cmd { mainWidth = innerWidth - sidebarWidth p.chatHeight = height - p.inputHeight p.sidebar.SetMode(sidebar.ModeVertical) - cmds = append(cmds, p.sidebar.SetSize(sidebarWidth, p.chatHeight)) + cmds = append(cmds, p.sidebar.SetSize(sidebarWidth, p.chatHeight), p.messages.SetPosition(0, 0)) } else { const horizontalSidebarHeight = 3 mainWidth = innerWidth p.chatHeight = height - p.inputHeight - horizontalSidebarHeight p.sidebar.SetMode(sidebar.ModeHorizontal) - cmds = append(cmds, p.sidebar.SetSize(width, horizontalSidebarHeight)) + cmds = append(cmds, p.sidebar.SetSize(width, horizontalSidebarHeight), p.messages.SetPosition(0, horizontalSidebarHeight)) } // Set component sizes