Skip to content

Commit

Permalink
update directory size on shortcut keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakenelf committed Sep 23, 2021
1 parent c8edb0a commit ebe42a4
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions internal/ui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

return m, nil

// A directoryItemSizeMsg is received anytime a new file is selected
// in the dirtree returning the file size as a string.
case directoryItemSizeMsg:
m.statusBar.SetItemSize(string(msg))

Expand Down Expand Up @@ -207,11 +209,13 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.dirTree.GoUp()
m.scrollPrimaryPane()
m.primaryPane.SetContent(m.dirTree.View())
} else {
// Secondary pane is active so scroll its content up.
m.secondaryPane.LineUp(3)
m.statusBar.SetItemSize("")

return m, m.getDirectoryItemSize(m.dirTree.GetSelectedFile().Name())
}

m.secondaryPane.LineUp(3)

return m, nil

case tea.MouseWheelDown:
Expand All @@ -221,11 +225,13 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.dirTree.GoDown()
m.scrollPrimaryPane()
m.primaryPane.SetContent(m.dirTree.View())
} else {
// Secondary pane is active so scroll its content down.
m.secondaryPane.LineDown(3)
m.statusBar.SetItemSize("")

return m, m.getDirectoryItemSize(m.dirTree.GetSelectedFile().Name())
}

m.secondaryPane.LineDown(3)

return m, nil
}

Expand All @@ -239,11 +245,13 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.dirTree.GotoTop()
m.primaryPane.GotoTop()
m.primaryPane.SetContent(m.dirTree.View())
} else {
// Secondary pane is active so go to the top.
m.secondaryPane.GotoTop()
m.statusBar.SetItemSize("")

return m, m.getDirectoryItemSize(m.dirTree.GetSelectedFile().Name())
}

m.secondaryPane.GotoTop()

return m, nil
}

Expand All @@ -265,6 +273,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if !m.showCommandBar && m.primaryPane.GetIsActive() {
m.statusBar.SetItemSize("")
m.previousDirectory, _ = directory.GetWorkingDirectory()

return m, m.updateDirectoryListing(
fmt.Sprintf("%s/%s", m.previousDirectory, directory.PreviousDirectory),
)
Expand Down Expand Up @@ -306,6 +315,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.dirTree.GetSelectedFile().IsDir() && !m.statusBar.CommandBarFocused() {
m.statusBar.SetItemSize("")
currentDir, _ := directory.GetWorkingDirectory()

return m, m.updateDirectoryListing(
fmt.Sprintf("%s/%s", currentDir, m.dirTree.GetSelectedFile().Name()),
)
Expand All @@ -324,11 +334,13 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.dirTree.GotoBottom()
m.primaryPane.GotoBottom()
m.primaryPane.SetContent(m.dirTree.View())
} else {
// Secondary pane is active so go to the bottom of it.
m.secondaryPane.GotoBottom()
m.statusBar.SetItemSize("")

return m, m.getDirectoryItemSize(m.dirTree.GetSelectedFile().Name())
}

m.secondaryPane.GotoBottom()

case key.Matches(msg, m.keys.Enter):
// If pressing enter while in move mode.
if m.inMoveMode {
Expand Down

0 comments on commit ebe42a4

Please sign in to comment.