Skip to content

#8898 Selection ignored in Ketcher API calls#8901

Merged
AlexeyGirin merged 10 commits into
masterfrom
copilot/fix-ketcher-api-selection-issue
Dec 15, 2025
Merged

#8898 Selection ignored in Ketcher API calls#8901
AlexeyGirin merged 10 commits into
masterfrom
copilot/fix-ketcher-api-selection-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 10, 2025

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

Selection data in KET files is preserved through the initiallySelected flag on atoms/bonds during deserialization. The UI's "Open as New Project" workflow restores this selection after loading, but the API methods (setMolecule, addFragment) did not.

Changes:

  • Added getSelectionFromStruct() helper that extracts selection from entities with initiallySelected flags
  • Updated setMolecule() and addFragment() to restore selection after loading and clean up flags

Before:

await ketcher.setMolecule(ketFileWithSelection);
// Selection is lost - initiallySelected flags set but never used

After:

await ketcher.setMolecule(ketFileWithSelection);
// Selection properly restored and flags cleaned up

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>Selection ignored in Ketcher API calls</issue_title>
<issue_description>Steps to Reproduce

  1. Open Ketcher
  2. Open browser dev tools
  3. Call Ketcher setMolecule or addFragment api and pass ket file with selected atoms and bonds to it.
    example.ket.zip

Actual behavior
Molecule drawn on canvas, but atoms and bonds are not selected.

Expected behavior
Atoms and bonds are selected.

Ketcher version [e.g. v2.4.2].
3.11.0-rc.2

Additional context
It works as expected with same ket file if it is opened through Ketcher UI "Open file" > "Open as New Project"</issue_description>

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


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

Copilot AI and others added 4 commits December 10, 2025 11:01
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix selection issue in Ketcher API calls Fix selection ignored in setMolecule and addFragment API calls Dec 10, 2025
Copilot AI requested a review from AlexeyGirin December 10, 2025 11:14
@KristinaKasyanovskaya KristinaKasyanovskaya marked this pull request as ready for review December 10, 2025 13:45
@AlexeyGirin AlexeyGirin merged commit 79e0772 into master Dec 15, 2025
14 of 15 checks passed
@AlexeyGirin AlexeyGirin deleted the copilot/fix-ketcher-api-selection-issue branch December 15, 2025 08:02
@AlexeyGirin AlexeyGirin changed the title Fix selection ignored in setMolecule and addFragment API calls #8898 Selection ignored in Ketcher API calls Dec 18, 2025
AlexeyGirin added a commit that referenced this pull request Jan 3, 2026
* Initial plan

* Add selection restoration for setMolecule and addFragment API methods

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* Add unit tests for getSelectionFromStruct function

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* Add code comments explaining selection entity types

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* Fix unused variable warning in test

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>

* refactor code

* refactor: consolidate getSelectionFromStruct and extract selectableEntities

* fix: fix import

* fix: fix code

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>
Co-authored-by: KristinaKasyanovskaya <kristina_kasyanovskaya@epam.com>
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.

Selection ignored in Ketcher API calls

4 participants