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
12 changes: 12 additions & 0 deletions pkg/ui/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type KeyMap struct {
ToggleNode key.Binding
Up key.Binding
Down key.Binding
Bottom key.Binding
Top key.Binding
NextFile key.Binding
PrevFile key.Binding
CtrlD key.Binding
Expand Down Expand Up @@ -45,6 +47,14 @@ var keys = &KeyMap{
key.WithKeys("down", "j"),
key.WithHelp("↓/j", "next file"),
),
Bottom: key.NewBinding(
key.WithKeys("G"),
key.WithHelp("G", "bottom"),
),
Top: key.NewBinding(
key.WithKeys("g"),
key.WithHelp("g", "top"),
),
NextFile: key.NewBinding(
key.WithKeys("n"),
key.WithHelp("n", "next file"),
Expand Down Expand Up @@ -108,6 +118,8 @@ func KeyGroups() [][]key.Binding {
keys.SwitchPanel,
keys.Up,
keys.Down,
keys.Top,
keys.Bottom,
keys.NextFile,
keys.PrevFile,
keys.CtrlD,
Expand Down
10 changes: 10 additions & 0 deletions pkg/ui/panes/diffviewer/diffviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ func (m *Model) ScrollDown(lines int) {
m.vp.ScrollDown(lines)
}

// ScrollBottom scrolls the viewport to the bottom.
func (m *Model) ScrollBottom() {
m.vp.GotoBottom()
}

// ScrollTop scrolls the viewport to its top.
func (m *Model) ScrollTop() {
m.vp.GotoTop()
}

func diffFile(node *cachedNode, width int, sideBySide bool) tea.Cmd {
if width == 0 || node == nil || len(node.files) != 1 {
return nil
Expand Down
8 changes: 8 additions & 0 deletions pkg/ui/panes/filetree/filetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ func (m *Model) Up() {
m.t.Up()
}

func (m *Model) GoToBottom() {
m.t.GoToBottom()
}

func (m *Model) GoToTop() {
m.t.GoToTop()
}

// NextFile moves the cursor to the next file node, skipping directories.
func (m *Model) NextFile() bool {
curr := m.t.NodeAtCurrentOffset()
Expand Down
39 changes: 33 additions & 6 deletions pkg/ui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,32 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds = append(cmds, cmd)
case key.Matches(msg, keys.Up):
if m.activePanel == FileTreePanel {
m, cmd = m.moveCursor(-1)
m, cmd = m.moveCursor(moveUp)
cmds = append(cmds, cmd)
} else {
m.diffViewer.ScrollUp(1)
}
case key.Matches(msg, keys.Down):
if m.activePanel == FileTreePanel {
m, cmd = m.moveCursor(1)
m, cmd = m.moveCursor(moveDown)
cmds = append(cmds, cmd)
} else {
m.diffViewer.ScrollDown(1)
}
case key.Matches(msg, keys.Bottom):
if m.activePanel == FileTreePanel {
m, cmd = m.moveCursor(moveBottom)
cmds = append(cmds, cmd)
} else {
m.diffViewer.ScrollBottom()
}
case key.Matches(msg, keys.Top):
if m.activePanel == FileTreePanel {
m, cmd = m.moveCursor(moveTop)
cmds = append(cmds, cmd)
} else {
m.diffViewer.ScrollTop()
}
case key.Matches(msg, keys.Copy):
cmd = m.fileTree.CopyCurrNodePath()
if cmd != nil {
Expand Down Expand Up @@ -1293,13 +1307,26 @@ func (m mainModel) moveToFile(movement int) (mainModel, tea.Cmd) {
return m, cmd
}

func (m mainModel) moveCursor(movement int) (mainModel, tea.Cmd) {
type movement int

const (
moveUp movement = iota
moveDown
moveBottom
moveTop
)

func (m mainModel) moveCursor(move movement) (mainModel, tea.Cmd) {
var cmd tea.Cmd
switch movement {
case -1:
switch move {
case moveUp:
m.fileTree.Up()
case 1:
case moveDown:
m.fileTree.Down()
case moveBottom:
m.fileTree.GoToBottom()
case moveTop:
m.fileTree.GoToTop()
}

node := m.fileTree.GetCurrNode()
Expand Down
Loading