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>
This commit is contained in:
copilot-swe-agent[bot]
2026-05-18 08:44:07 +00:00
committed by GitHub
parent 6da5bae945
commit 7af3f4ee83
3 changed files with 25 additions and 6 deletions
+20 -3
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)
+1 -1
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
+4 -2
View File
@@ -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.`)
}