Merge branch 'copilot/refactor-dnd-kitten-tracking' of https://github.com/kovidgoyal/kitty

This commit is contained in:
Kovid Goyal
2026-05-18 14:19:11 +05:30
3 changed files with 29 additions and 6 deletions

View File

@@ -550,8 +550,23 @@ func (dnd *dnd) end_drop(success bool) {
}
}
func (dnd *dnd) count_files_in_drop() int {
n := 0
for _, u := range dnd.drop_status.uri_list {
if (u.kind == parsed_uri_file && u.path != "") || u.kind == parsed_uri_data {
n++
}
}
for mime, d := range dnd.drop_dests {
if mime != "text/uri-list" && d.completed {
n++
}
}
return n
}
func (dnd *dnd) all_drop_data_received() (err error) {
dnd.data_has_been_dropped = true
dnd.num_dropped_files = dnd.count_files_in_drop()
var staging_dir *os.File
if dnd.drop_status.dropping_to != nil {
staging_dir = dnd.drop_status.dropping_to.handle
@@ -615,7 +630,7 @@ func (dnd *dnd) new_tdir() (dir_file *os.File, err error) {
func (dnd *dnd) all_mime_data_dropped() (err error) {
drop_status := &dnd.drop_status
if len(drop_status.uri_list) == 0 {
dnd.data_has_been_dropped = true
dnd.num_dropped_files = dnd.count_files_in_drop()
dnd.end_drop(true)
return dnd.render_screen()
}
@@ -913,7 +928,9 @@ func (dnd *dnd) drop_confirm(accepted bool) error {
dnd.confirm_drop.overwrites = nil
dnd.confirm_drop.staging_dir = nil
defer staging_dir.Close()
dnd.data_has_been_dropped = accepted
if !accepted {
dnd.num_dropped_files = 0
}
if accepted {
if err := rename_contents(staging_dir, dnd.drop_output_dir); err != nil {
dnd.end_drop(false)

View File

@@ -91,7 +91,7 @@ type dnd struct {
base_tempdir *os.File
tdir_counter int
is_case_sensitive_filesystem bool
data_has_been_dropped bool
num_dropped_files int
drag_status drag_status
in_test_mode bool
copy_button_region, move_button_region button_region

View File

@@ -107,8 +107,14 @@ func (dnd *dnd) render_screen() error {
next_line()
}
if dnd.allow_drops {
if dnd.data_has_been_dropped {
render_paragraph(`Data has been successfully dropped. You can drop more data or press Esc to quit.`)
if dnd.num_dropped_files > 0 {
verb := "have"
noun := "files"
if dnd.num_dropped_files == 1 {
verb = "has"
noun = "file"
}
render_paragraph(fmt.Sprintf(`%d %s %s been dropped in the last drop event. You can drop more data or press Esc to quit.`, dnd.num_dropped_files, noun, verb))
} else {
render_paragraph(`Drag some data from another application into this window to transfer the files here.`)
}