#7546 - Canvas does not reset scroll position after using “Clear canvas” - added monomers appear offset#9561
Open
#7546 - Canvas does not reset scroll position after using “Clear canvas” - added monomers appear offset#9561
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, callingdrawScrollBars()leaves no scrollbar rects (e.g. no elements matchingrect[data-testid$="-bar"]).screen-capture.6.webm
Check list
#1234 – issue name