diff --git a/pkg/ui/panes/diffviewer/diffviewer.go b/pkg/ui/panes/diffviewer/diffviewer.go index c69c7bf..6abad6b 100644 --- a/pkg/ui/panes/diffviewer/diffviewer.go +++ b/pkg/ui/panes/diffviewer/diffviewer.go @@ -67,18 +67,6 @@ func (m Model) Init() tea.Cmd { func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { cmds := make([]tea.Cmd, 0) switch msg := msg.(type) { - case tea.KeyMsg: - switch msg.String() { - case "down", "j", "n": - break - case "up", "k", "N", "p": - break - default: - vp, vpCmd := m.vp.Update(msg) - cmds = append(cmds, vpCmd) - m.vp = vp - } - case diffContentMsg: // Truncate lines to viewport width to prevent ANSI escape overflow. lines := strings.Split(msg.text, "\n") @@ -94,6 +82,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { m.vp.SetContent(diff) } + vp, vpCmd := m.vp.Update(msg) + cmds = append(cmds, vpCmd) + m.vp = vp + return m, tea.Batch(cmds...) } diff --git a/pkg/ui/tui.go b/pkg/ui/tui.go index feb7bda..e476657 100644 --- a/pkg/ui/tui.go +++ b/pkg/ui/tui.go @@ -313,6 +313,17 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if cmd != nil { cmds = append(cmds, cmd) } + case key.Matches(msg, keys.CtrlD, keys.CtrlU): + m.diffViewer, cmd = m.diffViewer.Update(msg) + cmds = append(cmds, cmd) + default: + if m.activePanel == DiffViewerPanel { + m.diffViewer, cmd = m.diffViewer.Update(msg) + cmds = append(cmds, cmd) + } else { + m.fileTree.Update(msg) + cmds = append(cmds, cmd) + } } case tea.WindowSizeMsg: @@ -381,25 +392,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case common.ErrMsg: fmt.Printf("Error: %v\n", msg.Err) log.Fatal(msg.Err) - } - // Route messages: key messages go only to active panel, other messages go to both. - // Exception: ctrl+d/ctrl+u go to diffViewer for scrolling (unless an overlay is open). - switch msg := msg.(type) { - case tea.KeyMsg: - switch msg.String() { - case "ctrl+d", "ctrl+u": - m.diffViewer, cmd = m.diffViewer.Update(msg) - cmds = append(cmds, cmd) - default: - if m.activePanel == DiffViewerPanel { - m.diffViewer, cmd = m.diffViewer.Update(msg) - cmds = append(cmds, cmd) - } else { - m.fileTree.Update(msg) - cmds = append(cmds, cmd) - } - } default: m.diffViewer, cmd = m.diffViewer.Update(msg) cmds = append(cmds, cmd) @@ -407,6 +400,9 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds = append(cmds, cmd) } + // Route messages: key messages go only to active panel, other messages go to both. + // Exception: ctrl+d/ctrl+u go to diffViewer for scrolling (unless an overlay is open). + return m, tea.Batch(cmds...) } @@ -1338,6 +1334,10 @@ func (m mainModel) moveCursor(move movement) (mainModel, tea.Cmd) { func (m mainModel) setNodeDiff(node *tree.Node) (mainModel, tea.Cmd) { var cmd tea.Cmd + if node == nil { + return m, nil + } + switch val := node.GivenValue().(type) { case *filenode.FileNode: m.diffViewer, cmd = m.diffViewer.SetFilePatch(val.File)