mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Implement Tab to change current dir
This commit is contained in:
@@ -3,6 +3,7 @@ package choose_files
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -53,6 +54,13 @@ func (s *State) SetSearchText(val string) {
|
||||
s.current_idx = 0
|
||||
}
|
||||
}
|
||||
func (s *State) SetCurrentDir(val string) {
|
||||
if s.CurrentDir() != val {
|
||||
s.search_text = ""
|
||||
s.current_idx = 0
|
||||
s.current_dir = val
|
||||
}
|
||||
}
|
||||
func (s State) ExcludePatterns() []*regexp.Regexp { return s.exclude_patterns }
|
||||
func (s State) ScorePatterns() []ScorePattern { return s.score_patterns }
|
||||
func (s State) CurrentIndex() int { return s.current_idx }
|
||||
@@ -129,6 +137,21 @@ func (h *Handler) OnKeyEvent(ev *loop.KeyEvent) (err error) {
|
||||
h.draw_screen()
|
||||
case ev.MatchesPressOrRepeat("esc") || ev.MatchesPressOrRepeat("ctrl+c"):
|
||||
h.lp.Quit(1)
|
||||
case ev.MatchesPressOrRepeat("tab"):
|
||||
matches, in_progress := h.get_results()
|
||||
if len(matches) > 0 && !in_progress {
|
||||
if idx := h.state.CurrentIndex(); idx < len(matches) {
|
||||
m := matches[idx].abspath
|
||||
if st, err := os.Stat(m); err == nil {
|
||||
if !st.IsDir() {
|
||||
m = filepath.Dir(m)
|
||||
}
|
||||
h.state.SetCurrentDir(m)
|
||||
return h.draw_screen()
|
||||
}
|
||||
}
|
||||
}
|
||||
h.lp.Beep()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
var _ = fmt.Print
|
||||
|
||||
func (h *Handler) draw_results_title() {
|
||||
text := filepath.Clean(h.state.BaseDir())
|
||||
text := filepath.Clean(h.state.CurrentDir())
|
||||
home := filepath.Clean(utils.Expanduser("~"))
|
||||
if strings.HasPrefix(text, home) {
|
||||
text = "~" + text[len(home):]
|
||||
|
||||
Reference in New Issue
Block a user