From 0f67ff37dfeb54460764193a35af82c47cfebaa6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 24 Jul 2025 08:19:27 +0530 Subject: [PATCH] Allow accepting the currently displayed parent directory by pressing ctrl+enter --- docs/kittens/choose-files.rst | 11 +++++++++++ kittens/choose_files/main.go | 6 ++++-- kittens/choose_files/main.py | 4 +++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/kittens/choose-files.rst b/docs/kittens/choose-files.rst index fdf4cc91a..d20696e0d 100644 --- a/docs/kittens/choose-files.rst +++ b/docs/kittens/choose-files.rst @@ -82,6 +82,17 @@ you want the file to be in (using the :kbd:`Tab` key), press :kbd:`Ctrl+Enter` and you will be able to type in the file name. +Selecting directories +--------------------------- + +This kitten can also be used to select directories, +for an :guilabel:`Open directory` type of dialog using :option:`--mode `:code:`=dir`. Once you have changed to the directory +you want, press :kbd:`Ctrl+Enter` to accept it. Or if you are in a parent +directory you can select a descendant directory by pressing :kbd:`Enter`, the +same as you would for selecting a file to open. + + Configuration ------------------------ diff --git a/kittens/choose_files/main.go b/kittens/choose_files/main.go index 5efa080e2..7678ff3c8 100644 --- a/kittens/choose_files/main.go +++ b/kittens/choose_files/main.go @@ -104,7 +104,6 @@ type render_state struct { type State struct { base_dir string current_dir string - select_dirs bool multiselect bool search_text string mode Mode @@ -142,7 +141,6 @@ func (s State) SortByLastModified() bool { return s.sort_by_last_mo func (s State) GlobalIgnores() ignorefiles.IgnoreFile { return s.global_ignores } func (s State) BaseDir() string { return utils.IfElse(s.base_dir == "", default_cwd, s.base_dir) } func (s State) Filter() Filter { return s.filter_map[s.current_filter] } -func (s State) SelectDirs() bool { return s.select_dirs } func (s State) Multiselect() bool { return s.multiselect } func (s State) String() string { return utils.Repr(s) } func (s State) SearchText() string { return s.search_text } @@ -483,6 +481,10 @@ func (h *Handler) dispatch_action(name, args string) (err error) { } case "typename": if !h.state.mode.CanSelectNonExistent() { + if h.state.mode.OnlyDirs() { + h.state.AddSelection(h.state.CurrentDir()) + return h.finish_selection() + } h.lp.Beep() } else { return h.switch_to_save_file_name_mode() diff --git a/kittens/choose_files/main.py b/kittens/choose_files/main.py index 2726a7deb..84e0a33de 100644 --- a/kittens/choose_files/main.py +++ b/kittens/choose_files/main.py @@ -82,7 +82,9 @@ it. Similarly, the :kbd:`Alt` key can be held to click and extend the range of s ''') map('Type file name', 'typename ctrl+enter typename', long_text=''' Type a file name/path rather than filtering the list of existing files. -Useful when specifying a file name for saving that does not yet exist. +Useful when specifying a file or directory name for saving that does not yet exist. +When choosing existing directories, will accept the directory whoose +contents are being currently displayed as the choice. Does not work when selecting files to open rather than to save. ''')