Skip to content

#7546 - Canvas does not reset scroll position after using “Clear canvas” - added monomers appear offset#9561

Open
gitquil07 wants to merge 7 commits intomasterfrom
hide-scrollbar-after-canvas-clean
Open

#7546 - Canvas does not reset scroll position after using “Clear canvas” - added monomers appear offset#9561
gitquil07 wants to merge 7 commits intomasterfrom
hide-scrollbar-after-canvas-clean

Conversation

@gitquil07
Copy link
Copy Markdown
Collaborator

@gitquil07 gitquil07 commented Mar 26, 2026

How the feature works? / How did you fix the issue?

(Screenshots, videos, or GIFs, if applicable)

Clear canvas: zoom & scrollbars (macromolecules)

Issue

In macromolecules (e.g. popup mode), after adding monomers the canvas could zoom and scroll as expected. After Clear canvas, the view was wrong: custom SVG scrollbars stayed visible on an empty canvas, the pan/zoom state was not reset, and new monomers appeared offset from the usual default position instead of at the normal starting point.

Resolution (code changes)

1. Reset zoom when clearing (ClearTool, ketcher-core)

After the model is cleared and the render is updated, ZoomTool.instance.resetZoom() is invoked so the zoom/pan transform returns to the default state for an empty canvas.

2. Do not draw scrollbars on an empty canvas (ZoomTool.drawScrollBars(), ketcher-core)

If the drawing layer (e.g. <g class="drawn-structures">) has no child nodes, the code skips scrollbar rendering: it removes any existing horizontal/vertical scrollbar elements and returns early. That avoids incorrect scrollbar layout when there is no content and hides scrollbars when nothing is drawn.

3. Unit test (ZoomTool.test.ts, ketcher-core)

A test verifies that after clearing children under .drawn-structures, calling drawScrollBars() leaves no scrollbar rects (e.g. no elements matching rect[data-testid$="-bar"]).

screen-capture.6.webm

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

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.

Canvas does not reset scroll position after using “Clear canvas” - added monomers appear offset

1 participant