Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions pkg/ui/panes/diffviewer/diffviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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...)
}

Expand Down
36 changes: 18 additions & 18 deletions pkg/ui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -381,32 +392,17 @@ 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)
m.fileTree.Update(msg)
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...)
}

Expand Down Expand Up @@ -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)
Expand Down
Loading