Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 3, 2025

Overview

This PR enables users to replace existing images by dragging and dropping new images onto them, improving the workflow for editing and updating images in the application.

Problem

Previously, the drag-and-drop functionality only worked on empty/default canvas panels. When users tried to drag and drop a new image onto a canvas that already contained an image, nothing would happen. The only way to replace an image was to delete the existing layer and create a new one, which was inefficient.

Solution

Modified the drop event handler in imgkit/index.js to:

  1. Accept drops on all canvas states (both empty and full)
  2. Load the dropped image into the target canvas, replacing any existing image
  3. Only create a new empty layer when dropping on an empty canvas (preserving the original behavior)

Technical Changes

File Modified: imgkit/index.js (lines 348-383)

The key change was restructuring the drop event listener:

  • Before: Wrapped all logic in if (this.canvas.id !== "full") which blocked drops on existing images
  • After: Moved createDefaultImage() call inside a conditional check, allowing drops on all canvases while only creating new layers when appropriate

Behavior

Before

  • ✅ Drop on empty canvas → loads image, creates new layer
  • ❌ Drop on existing image → blocked, nothing happens

After

  • ✅ Drop on empty canvas → loads image, creates new layer (unchanged)
  • ✅ Drop on existing image → replaces image, no new layer created (new feature)

Testing

  • ✅ Build completes successfully with no errors
  • ✅ Syntax validated
  • ✅ No breaking changes to existing functionality
  • ✅ Both file path and ArrayBuffer-based drops supported

This change provides a more intuitive user experience by allowing quick image replacement through drag and drop, reducing the number of steps needed to update an image in the workspace.

Original prompt

This section details on the original issue you should resolve

<issue_title>feat: Enable image replacement via drag and drop</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #48

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 3, 2025 12:25
Co-authored-by: volta2030 <65960990+volta2030@users.noreply.github.com>
Co-authored-by: volta2030 <65960990+volta2030@users.noreply.github.com>
Copilot AI changed the title [WIP] feat: Enable image replacement via drag and drop feat: Enable image replacement via drag and drop Oct 3, 2025
Copilot AI requested a review from volta2030 October 3, 2025 12:32
@volta2030 volta2030 marked this pull request as ready for review October 3, 2025 12:46
@volta2030
Copy link
Member

LGTM

@volta2030 volta2030 merged commit 7793af2 into develop Oct 3, 2025
@volta2030 volta2030 deleted the copilot/fix-a09b4953-2d6f-4c5e-954a-45c5b3119164 branch October 3, 2025 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Enable image replacement via drag and drop

2 participants