Skip to content

Commit

Permalink
reset previous key
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakenelf committed Oct 18, 2021
1 parent 65df4f6 commit 66f5484
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions internal/ui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, m.keys.Left):
if !m.showCommandInput && m.primaryPane.GetIsActive() {
m.statusBar.SetItemSize("")
m.previousKey = tea.KeyMsg{}
previousDirectory, err := dirfs.GetWorkingDirectory()
if err != nil {
return m, m.handleErrorCmd(err)
Expand All @@ -293,6 +294,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.updateStatusBarContent()
m.primaryPane.SetContent(m.dirTree.View())
m.statusBar.SetItemSize("")
m.previousKey = tea.KeyMsg{}

return m, m.getDirectoryItemSizeCmd(m.dirTree.GetSelectedFile().Name())
}
Expand All @@ -307,6 +309,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.updateStatusBarContent()
m.primaryPane.SetContent(m.dirTree.View())
m.statusBar.SetItemSize("")
m.previousKey = tea.KeyMsg{}

return m, m.getDirectoryItemSizeCmd(m.dirTree.GetSelectedFile().Name())
}
Expand All @@ -316,6 +319,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Open directory or read file content and display in secondary pane.
case key.Matches(msg, m.keys.Right):
if !m.showCommandInput && m.primaryPane.GetIsActive() && m.dirTree.GetTotalFiles() > 0 {
m.previousKey = tea.KeyMsg{}

switch {
case m.dirTree.GetSelectedFile().IsDir() && !m.statusBar.CommandBarFocused():
m.statusBar.SetItemSize("")
Expand Down Expand Up @@ -364,6 +369,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.primaryPane.GotoBottom()
m.primaryPane.SetContent(m.dirTree.View())
m.statusBar.SetItemSize("")
m.previousKey = tea.KeyMsg{}

return m, m.getDirectoryItemSizeCmd(m.dirTree.GetSelectedFile().Name())
}
Expand All @@ -372,6 +378,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

// process command bar input.
case key.Matches(msg, m.keys.Enter):
m.previousKey = tea.KeyMsg{}

switch {
case m.moveMode:
return m, m.moveDirectoryItemCmd(m.itemToMove.Name())
Expand All @@ -397,6 +405,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Delete the currently selected item.
case key.Matches(msg, m.keys.Delete):
if !m.showCommandInput && m.primaryPane.GetIsActive() {
m.previousKey = tea.KeyMsg{}

if m.dirTree.GetSelectedFile().IsDir() {
return m, tea.Sequentially(
m.deleteDirectoryCmd(m.dirTree.GetSelectedFile().Name()),
Expand All @@ -417,6 +427,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.showCommandInput = true
m.statusBar.FocusCommandBar()
m.updateStatusBarContent()
m.previousKey = tea.KeyMsg{}

return m, nil
}
Expand All @@ -428,6 +439,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.showCommandInput = true
m.statusBar.FocusCommandBar()
m.updateStatusBarContent()
m.previousKey = tea.KeyMsg{}

return m, nil
}
Expand All @@ -439,6 +451,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.showCommandInput = true
m.statusBar.FocusCommandBar()
m.updateStatusBarContent()
m.previousKey = tea.KeyMsg{}

return m, nil
}
Expand All @@ -447,6 +460,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// command bar is not curently open.
case key.Matches(msg, m.keys.OpenHomeDirectory):
if !m.showCommandInput {
m.previousKey = tea.KeyMsg{}
homeDir, err := dirfs.GetHomeDirectory()
if err != nil {
return m, m.handleErrorCmd(err)
Expand All @@ -458,25 +472,32 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Shortcut to go back to the previous directory.
case key.Matches(msg, m.keys.OpenPreviousDirectory):
if !m.showCommandInput && m.previousDirectory != "" {
m.previousKey = tea.KeyMsg{}

return m, m.updateDirectoryListingCmd(m.previousDirectory)
}

// Shortcut to go back to the root directory.
case key.Matches(msg, m.keys.OpenRootDirectory):
if !m.showCommandInput {
m.previousKey = tea.KeyMsg{}

return m, m.updateDirectoryListingCmd(dirfs.RootDirectory)
}

// Toggle hidden files and folders.
case key.Matches(msg, m.keys.ToggleHidden):
if !m.showCommandInput && m.primaryPane.GetIsActive() {
m.dirTree.ToggleHidden()
m.previousKey = tea.KeyMsg{}

return m, m.updateDirectoryListingCmd(dirfs.CurrentDirectory)
}

// Toggle between the two panes if the command bar is not currently active.
case key.Matches(msg, m.keys.Tab):
if !m.showCommandInput {
m.previousKey = tea.KeyMsg{}
m.primaryPane.SetActive(!m.primaryPane.GetIsActive())
m.secondaryPane.SetActive(!m.secondaryPane.GetIsActive())
}
Expand All @@ -485,6 +506,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, m.keys.EnterMoveMode):
if !m.showCommandInput && m.primaryPane.GetIsActive() && m.dirTree.GetTotalFiles() > 0 {
m.moveMode = true
m.previousKey = tea.KeyMsg{}
m.primaryPane.ShowAlternateBorder(true)
initialMoveDirectory, err := dirfs.GetWorkingDirectory()
if err != nil {
Expand All @@ -499,6 +521,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Zip up the currently selected item.
case key.Matches(msg, m.keys.Zip):
if !m.showCommandInput && m.primaryPane.GetIsActive() && m.dirTree.GetTotalFiles() > 0 {
m.previousKey = tea.KeyMsg{}

return m, tea.Sequentially(
m.zipDirectoryCmd(m.dirTree.GetSelectedFile().Name()),
m.updateDirectoryListingCmd(dirfs.CurrentDirectory),
Expand All @@ -508,6 +532,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Unzip the currently selected zip file.
case key.Matches(msg, m.keys.Unzip):
if !m.showCommandInput && m.primaryPane.GetIsActive() && m.dirTree.GetTotalFiles() > 0 {
m.previousKey = tea.KeyMsg{}

return m, tea.Sequentially(
m.unzipDirectoryCmd(m.dirTree.GetSelectedFile().Name()),
m.updateDirectoryListingCmd(dirfs.CurrentDirectory),
Expand All @@ -517,6 +543,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Copy the currently selected item.
case key.Matches(msg, m.keys.Copy):
if !m.showCommandInput && m.primaryPane.GetIsActive() && m.dirTree.GetTotalFiles() > 0 {
m.previousKey = tea.KeyMsg{}

if m.dirTree.GetSelectedFile().IsDir() {
return m, tea.Sequentially(
m.copyDirectoryCmd(m.dirTree.GetSelectedFile().Name()),
Expand All @@ -533,6 +561,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Edit the currently selected file.
case key.Matches(msg, m.keys.EditFile):
if !m.showCommandInput && m.primaryPane.GetIsActive() && !m.dirTree.GetSelectedFile().IsDir() {
m.previousKey = tea.KeyMsg{}

editorPath := os.Getenv("EDITOR")
if editorPath == "" {
return m, m.handleErrorCmd(errors.New("$EDITOR not set"))
Expand All @@ -557,6 +587,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

case key.Matches(msg, m.keys.PreviewDirectory):
if !m.showCommandInput && m.primaryPane.GetIsActive() && m.dirTree.GetSelectedFile().IsDir() {
m.previousKey = tea.KeyMsg{}

currentDir, err := dirfs.GetWorkingDirectory()
if err != nil {
return m, m.handleErrorCmd(err)
Expand All @@ -579,6 +611,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.createFileMode = false
m.createDirectoryMode = false
m.renameMode = false
m.previousKey = tea.KeyMsg{}
m.primaryPane.SetActive(true)
m.secondaryPane.SetActive(false)
m.statusBar.BlurCommandBar()
Expand Down

0 comments on commit 66f5484

Please sign in to comment.