Allow accepting the currently displayed parent directory by pressing ctrl+enter

This commit is contained in:
Kovid Goyal 2025-07-24 08:19:27 +05:30
parent 988070612b
commit 0f67ff37df
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 18 additions and 3 deletions

View file

@ -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 <kitty +kitten
choose_files --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
------------------------

View file

@ -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()

View file

@ -82,7 +82,9 @@
''')
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.
''')