Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 9, 2025

How did you fix the issue?

In Macromolecules mode, clicking "Clear Canvas" on an empty canvas created undo history entries, requiring multiple undo operations to restore a structure. Micro mode had no such issue due to a guard in the action handler.

Root cause: ClearTool unconditionally updated history regardless of canvas state. Macromolecules mode invokes ClearTool directly, bypassing the isBlank() check present in the ketcher-react action handler.

Fix: Added early return in ClearTool constructor when canvas is empty:

constructor(private readonly editor: CoreEditor) {
  this.editor = editor;

  // Only update history if there are entities to delete
  if (!this.editor.drawingEntitiesManager.hasDrawingEntities) {
    return;
  }

  this.history = new EditorHistory(editor);
  // ... rest of clear logic
}

This prevents history updates and object creation when clearing an already-empty canvas, making behavior consistent across both modes.

Check list

  • unit-tests written
  • e2e-tests written
  • documentation updated
  • PR name follows the pattern #1234 – issue name
  • branch name doesn't contain '#'
  • PR is linked with the issue
  • base branch (master or release/xx) is correct
  • task status changed to "Code review"
  • reviewers are notified about the pull request
Original prompt

This section details on the original issue you should resolve

<issue_title>After clicking the "Clear Canvas" button multiple times, a user has to click the "Undo" button multiple times to return the structure </issue_title>
<issue_description>Steps to Reproduce

  1. Select Macromolecules mode:
Image 2. Draw any structure on the canvas (for example click any structure in macromolecules library):

Image

  1. Click on the "Clear Canvas" button 5 times:
Image
  1. Click on the "Undo" button:
Image

Actual behavior
The structure does not return to the canvas. To make it appear again, "Undo" button needs to be clicked same number of times as "Clear Canvas" button, inconsistently with the Micro mode, where the structure returns after 1 click no matter how many times "Clear Canvas" was clicked. Note: issue is reproduced in all layout modes (sequence, snake, flex).

Expected behavior
The structure returns to the canvas after 1 click

Screenshots

2024-05-31_19h47_00.mp4

Related to #4543

Desktop (please complete the following information):

  • OS: Windows 10 Pro (version 22H2) x64
  • Browser: Сhrome
  • Version: (125.0.6422.113) x64

Ketcher version 2.21.0-rc.2, Build at 2024-05-31; 07:23:21</issue_description>

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

@d-mrzv Reproduced by agent - https://chatgpt.com/share/691608c7-6230-8002-bc7d-7a532a801346

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix undo functionality after multiple clear canvas clicks Fix multiple undo entries when Clear Canvas clicked repeatedly in Macromolecules mode Dec 9, 2025
Copilot AI requested a review from NikitaKuzminn December 9, 2025 09:50
@NikitaKuzminn NikitaKuzminn marked this pull request as ready for review December 10, 2025 12:59
@AlexeyGirin AlexeyGirin changed the title Fix multiple undo entries when Clear Canvas clicked repeatedly in Macromolecules mode #4724 After clicking the "Clear Canvas" button multiple times, a user has to click the "Undo" button multiple times to return the structure Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After clicking the "Clear Canvas" button multiple times, a user has to click the "Undo" button multiple times to return the structure

2 participants