mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-22 00:08:04 +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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user