mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-05-13 08:26:56 +00:00
kitten choose-files: Add a new binding of Alt+Enter to modify the name of an existing file when choosing a save file name
Fixes #9387
This commit is contained in:
parent
ada88e063b
commit
a5433b8994
5 changed files with 44 additions and 1 deletions
|
|
@ -205,6 +205,12 @@ Detailed list of changes
|
|||
- kitten @: Fix relative paths for --password-file being resolved relative to
|
||||
CWD instead of the kitty config directory
|
||||
|
||||
- kitten choose-files: Add a new binding of :kbd:`Alt+Enter` to modify the name
|
||||
of an existing file when choosing a save file name (:iss:`9387`)
|
||||
|
||||
- kitten choose-files: Fix TAB completion in the choose save file name prompt
|
||||
not working with respect to the current working directory (:iss:`9387`)
|
||||
|
||||
|
||||
0.45.0 [2025-12-24]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
|||
|
|
@ -99,7 +99,9 @@ This kitten can also be used to select non-existent files, that is a new file
|
|||
for a :guilabel:`Save file` type of dialog using :option:`--mode <kitty +kitten
|
||||
choose_files --mode>`:code:`=save-file`. Once you have changed to the directory
|
||||
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.
|
||||
press :kbd:`Ctrl+Enter` and you will be able to type in the file name. If you
|
||||
wish to modify an existing file name use :kbd:`Alt+Enter` to modify the
|
||||
filename of the current top match instead.
|
||||
|
||||
|
||||
Selecting directories
|
||||
|
|
|
|||
|
|
@ -479,6 +479,26 @@ func (h *Handler) switch_to_save_file_name_mode() error {
|
|||
if h.state.SearchText() != "" {
|
||||
name = h.state.SearchText()
|
||||
}
|
||||
if name == "" {
|
||||
name = h.current_abspath()
|
||||
if name != "" {
|
||||
if r, err := filepath.Rel(h.state.CurrentDir(), name); err == nil {
|
||||
name = r
|
||||
}
|
||||
}
|
||||
}
|
||||
h.initialize_save_file_name(name)
|
||||
return h.draw_screen()
|
||||
}
|
||||
|
||||
func (h *Handler) switch_to_save_file_name_mode_based_on_existing() error {
|
||||
name := h.current_abspath()
|
||||
if name == "" {
|
||||
return h.switch_to_save_file_name_mode()
|
||||
}
|
||||
if r, err := filepath.Rel(h.state.CurrentDir(), name); err == nil {
|
||||
name = r
|
||||
}
|
||||
h.initialize_save_file_name(name)
|
||||
return h.draw_screen()
|
||||
}
|
||||
|
|
@ -573,6 +593,12 @@ func (h *Handler) dispatch_action(name, args string) (err error) {
|
|||
} else {
|
||||
return h.switch_to_save_file_name_mode()
|
||||
}
|
||||
case "modifyname":
|
||||
if h.state.mode.CanSelectNonExistent() {
|
||||
return h.switch_to_save_file_name_mode_based_on_existing()
|
||||
} else {
|
||||
h.lp.Beep()
|
||||
}
|
||||
case "toggle":
|
||||
switch args {
|
||||
case "preview":
|
||||
|
|
|
|||
|
|
@ -133,6 +133,13 @@ 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.
|
||||
''')
|
||||
map('Modify file name', 'modifyname alt+enter modifyname', long_text='''
|
||||
Modify the name of an existing file and select it for saving.
|
||||
Useful when specifying a file or directory name for saving that does not yet exist,
|
||||
but is based on an existing file name.
|
||||
Does not work when selecting files to open rather than to save.
|
||||
''')
|
||||
|
||||
|
||||
map('Next result', 'next_result down next 1')
|
||||
map('Previous result', 'prev_result up next -1')
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ func FilePromptCompleter(getcwd func() string) func(string, string) *cli.Complet
|
|||
return ans
|
||||
}
|
||||
}
|
||||
debugprintln(1111111, getcwd())
|
||||
return func(before_cursor, after_cursor string) (ans *cli.Completions) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
|
@ -39,6 +40,7 @@ func FilePromptCompleter(getcwd func() string) func(string, string) *cli.Complet
|
|||
prefix = d + utils.IfElse(strings.HasSuffix(d, string(os.PathSeparator)), "", string(os.PathSeparator))
|
||||
}
|
||||
dir := ""
|
||||
debugprintln(2222222, getcwd())
|
||||
if path == "" {
|
||||
path = getcwd()
|
||||
dir = path
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue