diff --git a/main.go b/main.go index 6496b3b..c3e77ae 100644 --- a/main.go +++ b/main.go @@ -200,6 +200,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.chatViewMessageContainer.BorderForeground(util.NormalTabBorderColor).Width(m.terminalWidth / 3 * 2) } + chatContainerWidth := m.chatViewMessageContainer.GetWidth() + m.settingsModel, cmd = m.settingsModel.Update(util.MakeWindowResizeMsg(chatContainerWidth)) + cmds = append(cmds, cmd) + m.sessionModel, cmd = m.sessionModel.Update(util.MakeWindowResizeMsg(chatContainerWidth)) + cmds = append(cmds, cmd) + } switch msg.Type { @@ -266,11 +272,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.promptContainer = m.promptContainer.Copy().MaxWidth(m.terminalWidth). Width(m.terminalWidth - 2) - m.chatViewMessageContainer.Width(m.terminalWidth / 3 * 2) + widthToUse := m.terminalWidth / 3 * 2 + util.Log("viewMode:", m.viewMode) if m.viewMode == util.ZenMode { - m.chatViewMessageContainer.Width(m.terminalWidth - 2) + widthToUse = m.terminalWidth - 2 } + m.chatViewMessageContainer.Width(widthToUse) // TODO: get rid of this magic number promptContainerHeight := m.promptContainer.GetHeight() + 5 @@ -289,9 +297,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.viewport.Height = msg.Height - promptContainerHeight m.promptInput.Width = msg.Width - 3 } - yolo := m.chatViewMessageContainer.GetWidth() - m.settingsModel.Update(util.MakeWindowResizeMsg(yolo)) - m.sessionModel.Update(util.MakeWindowResizeMsg(yolo)) + + chatContainerWidth := m.chatViewMessageContainer.GetWidth() + m.settingsModel, cmd = m.settingsModel.Update(util.MakeWindowResizeMsg(chatContainerWidth)) + cmds = append(cmds, cmd) + m.sessionModel, cmd = m.sessionModel.Update(util.MakeWindowResizeMsg(chatContainerWidth)) + cmds = append(cmds, cmd) } if enableUpdateOfViewport { diff --git a/sessions/sessions.go b/sessions/sessions.go index 6240bec..d9d04fc 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -156,16 +156,13 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.list = initEditListViewTable(m.AllSessions, m.CurrentSessionID) m.currentEditID = -1 - return m, cmd case settings.UpdateSettingsEvent: m.Settings = msg.Settings - return m, nil case util.FocusEvent: m.isFocused = msg.IsFocused m.currentEditID = -1 - return m, nil case util.OurWindowResize: width := m.terminalWidth - msg.Width - 5 @@ -175,7 +172,6 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { // add the latest message to the array of messages util.Log("Processing message: ") cmd = m.handleMsgProcessing(msg) - return m, cmd case tea.WindowSizeMsg: m.terminalWidth = msg.Width diff --git a/settings/settings.go b/settings/settings.go index c3d90dd..8a11cb0 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -84,6 +84,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { switch msg := msg.(type) { case util.OurWindowResize: + util.Log("our Window resized", msg.Width) width := m.terminalWidth - msg.Width - 5 m.list.Width(width) @@ -100,20 +101,18 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { return m, nil case tea.WindowSizeMsg: m.terminalWidth = msg.Width - return m, nil + case tea.KeyMsg: // in order to do proper event bubbling, we don't actually want to handle // any keyboard events, unless we're the focused pane. - if !m.isFocused { - return m, nil - } - - if m.mode == viewMode { - cmd = m.handleViewMode(msg) - cmds = append(cmds, cmd) - } else { - cmd = m.handleEditMode(msg) - cmds = append(cmds, cmd) + if m.isFocused { + if m.mode == viewMode { + cmd = m.handleViewMode(msg) + cmds = append(cmds, cmd) + } else { + cmd = m.handleEditMode(msg) + cmds = append(cmds, cmd) + } } }