diff --git a/internal/ui/update.go b/internal/ui/update.go index 4f18e6e..722c161 100644 --- a/internal/ui/update.go +++ b/internal/ui/update.go @@ -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) @@ -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()) } @@ -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()) } @@ -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("") @@ -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()) } @@ -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()) @@ -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()), @@ -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 } @@ -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 } @@ -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 } @@ -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) @@ -458,12 +472,16 @@ 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) } @@ -471,12 +489,15 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { 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()) } @@ -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 { @@ -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), @@ -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), @@ -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()), @@ -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")) @@ -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) @@ -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()