mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-24 09:18:08 +02:00
Implement Tab to change current dir
This commit is contained in:
@@ -3,6 +3,7 @@ package choose_files
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -53,6 +54,13 @@ func (s *State) SetSearchText(val string) {
|
|||||||
s.current_idx = 0
|
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) ExcludePatterns() []*regexp.Regexp { return s.exclude_patterns }
|
||||||
func (s State) ScorePatterns() []ScorePattern { return s.score_patterns }
|
func (s State) ScorePatterns() []ScorePattern { return s.score_patterns }
|
||||||
func (s State) CurrentIndex() int { return s.current_idx }
|
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()
|
h.draw_screen()
|
||||||
case ev.MatchesPressOrRepeat("esc") || ev.MatchesPressOrRepeat("ctrl+c"):
|
case ev.MatchesPressOrRepeat("esc") || ev.MatchesPressOrRepeat("ctrl+c"):
|
||||||
h.lp.Quit(1)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import (
|
|||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
|
||||||
func (h *Handler) draw_results_title() {
|
func (h *Handler) draw_results_title() {
|
||||||
text := filepath.Clean(h.state.BaseDir())
|
text := filepath.Clean(h.state.CurrentDir())
|
||||||
home := filepath.Clean(utils.Expanduser("~"))
|
home := filepath.Clean(utils.Expanduser("~"))
|
||||||
if strings.HasPrefix(text, home) {
|
if strings.HasPrefix(text, home) {
|
||||||
text = "~" + text[len(home):]
|
text = "~" + text[len(home):]
|
||||||
|
|||||||
Reference in New Issue
Block a user