From 7af3f4ee83eafff653b9201459d4dd276bd29d3f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 18 May 2026 08:44:07 +0000 Subject: [PATCH] Refactor dnd kitten: track num_dropped_files instead of data_has_been_dropped Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/84513fee-68de-4504-b41b-e8643e0ea585 Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com> --- kittens/dnd/drop.go | 23 ++++++++++++++++++++--- kittens/dnd/main.go | 2 +- kittens/dnd/render.go | 6 ++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/kittens/dnd/drop.go b/kittens/dnd/drop.go index e85efab1d..c2b98932e 100644 --- a/kittens/dnd/drop.go +++ b/kittens/dnd/drop.go @@ -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) diff --git a/kittens/dnd/main.go b/kittens/dnd/main.go index b6bbf6867..5555af38f 100644 --- a/kittens/dnd/main.go +++ b/kittens/dnd/main.go @@ -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 diff --git a/kittens/dnd/render.go b/kittens/dnd/render.go index 234aba215..5e944fe85 100644 --- a/kittens/dnd/render.go +++ b/kittens/dnd/render.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/kovidgoyal/kitty/tools/tui/loop" + "github.com/kovidgoyal/kitty/tools/utils" "github.com/kovidgoyal/kitty/tools/wcswidth" ) @@ -107,8 +108,9 @@ 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 { + noun := utils.IfElse(dnd.num_dropped_files == 1, "file", "files") + 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, utils.IfElse(dnd.num_dropped_files == 1, "has", "have"))) } else { render_paragraph(`Drag some data from another application into this window to transfer the files here.`) }