mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 03:01:57 +02: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:
@@ -205,6 +205,12 @@ Detailed list of changes
|
|||||||
- kitten @: Fix relative paths for --password-file being resolved relative to
|
- kitten @: Fix relative paths for --password-file being resolved relative to
|
||||||
CWD instead of the kitty config directory
|
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]
|
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
|
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
|
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),
|
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
|
Selecting directories
|
||||||
|
|||||||
@@ -479,6 +479,26 @@ func (h *Handler) switch_to_save_file_name_mode() error {
|
|||||||
if h.state.SearchText() != "" {
|
if h.state.SearchText() != "" {
|
||||||
name = 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)
|
h.initialize_save_file_name(name)
|
||||||
return h.draw_screen()
|
return h.draw_screen()
|
||||||
}
|
}
|
||||||
@@ -573,6 +593,12 @@ func (h *Handler) dispatch_action(name, args string) (err error) {
|
|||||||
} else {
|
} else {
|
||||||
return h.switch_to_save_file_name_mode()
|
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":
|
case "toggle":
|
||||||
switch args {
|
switch args {
|
||||||
case "preview":
|
case "preview":
|
||||||
|
|||||||
@@ -133,6 +133,13 @@ When choosing existing directories, will accept the directory whoose
|
|||||||
contents are being currently displayed as the choice.
|
contents are being currently displayed as the choice.
|
||||||
Does not work when selecting files to open rather than to save.
|
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('Next result', 'next_result down next 1')
|
||||||
map('Previous result', 'prev_result up 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
|
return ans
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
debugprintln(1111111, getcwd())
|
||||||
return func(before_cursor, after_cursor string) (ans *cli.Completions) {
|
return func(before_cursor, after_cursor string) (ans *cli.Completions) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
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))
|
prefix = d + utils.IfElse(strings.HasSuffix(d, string(os.PathSeparator)), "", string(os.PathSeparator))
|
||||||
}
|
}
|
||||||
dir := ""
|
dir := ""
|
||||||
|
debugprintln(2222222, getcwd())
|
||||||
if path == "" {
|
if path == "" {
|
||||||
path = getcwd()
|
path = getcwd()
|
||||||
dir = path
|
dir = path
|
||||||
|
|||||||
Reference in New Issue
Block a user