Implement TODO in drag_add_mimes: populate ds.mimes from ds.mimes_buf

Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/b92ba12a-26f2-4a01-8ad9-665bbd90b98a

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-03 06:23:58 +00:00
committed by GitHub
parent f6339d0bbf
commit 0f4b673d02
3 changed files with 16 additions and 6 deletions

View File

@@ -874,8 +874,8 @@ drag_add_mimes(Window *w, int allowed_operations, const char *data, size_t sz, b
ds.offer_being_built = true;
size_t new_sz = ds.bufsz + sz;
if (new_sz > 1024 * 1024) { abrt(EFBIG); }
ds.mimes = realloc(ds.mimes, ds.bufsz + sz + 1);
if (!ds.mimes) { abrt(ENOMEM); }
ds.mimes_buf = realloc(ds.mimes_buf, ds.bufsz + sz + 1);
if (!ds.mimes_buf) { abrt(ENOMEM); }
memcpy(ds.mimes_buf + ds.bufsz, data, sz);
ds.bufsz = new_sz;
ds.mimes_buf[ds.bufsz] = 0;
@@ -889,9 +889,18 @@ drag_add_mimes(Window *w, int allowed_operations, const char *data, size_t sz, b
ds.mimes = calloc(rough_count + 1, sizeof(void*));
if (!ds.mimes) { abrt(ENOMEM); }
ds.num_mimes = 0;
// TODO: Populate ds.mimes with pointers to the mime strings in
// ds.mimes_buf and set ds.num_mimes to the number of such
// strings.
// ds.mimes_buf contains MIME strings separated by one or more NULL
// bytes and ends with a NULL byte; collect pointers to non-empty ones.
char *p = ds.mimes_buf, *end = ds.mimes_buf + ds.bufsz;
while (p < end) {
if (*p) {
if (ds.num_mimes >= rough_count + 1) break;
ds.mimes[ds.num_mimes++] = p;
p += strlen(p) + 1;
} else {
p++;
}
}
}
#undef abrt
}

View File

@@ -24,3 +24,4 @@ void dnd_set_test_write_func(PyObject *func);
void drag_free_offer(Window *w);
void drag_add_mimes(Window *w, int allowed_operations, const char *data, size_t sz, bool has_more);

View File

@@ -1538,7 +1538,7 @@ screen_handle_dnd_command(Screen *self, const DnDCommand *cmd, const uint8_t *pa
else drop_send_einval(w);
} break;
case 'o': {
if (cmd->payload_sz > 0) ;
if (cmd->payload_sz > 0) drag_add_mimes(w, (int)cmd->operation, (const char*)payload, cmd->payload_sz, cmd->more);
else w->drag_source.can_offer = true;
} break;
case 'O': {