Skip to content

Commit

Permalink
Fix bug with panes not resizing when switching modes
Browse files Browse the repository at this point in the history
  • Loading branch information
Taranveer Bains committed Mar 12, 2024
1 parent 58bfbe9 commit b592019
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
21 changes: 16 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand All @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions sessions/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 10 additions & 11 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
}

}
Expand Down

0 comments on commit b592019

Please sign in to comment.