Skip to content

Conversation

@MinCrohn
Copy link
Collaborator

The event handling for SelectionState has been refined to be more granular and intuitive.
The previous onSelect and onDragSelect callbacks made it difficult to clearly distinguish user intents (like single-click, double-click, and drag-select). This update introduces clearer event callbacks like onClick, onDoubleClick, and onDragEnd, making it easier to implement various interactions.

💥 Breaking Changes

  • onSelect callback has been removed from the SelectionState options.
  • onDragSelect callback has been removed from the SelectionState options.

✨ New Features (New Event Callbacks)

  • onDown: Called immediately when the user presses the pointer.
  • onUp: Called on pointer up after a click action (not a drag).
  • onClick: Called when the user clicks a target. (Not called on double-click)
  • onDoubleClick: Called when the user double-clicks a target.
  • onDragStart: Called once when a drag (multi-select) action starts.
  • onDrag: Called repeatedly while a drag action is in progress.
  • onDragEnd: Called when the drag action ends.
  • onOver: Called when the mouse pointer moves over an object.

📝 Usage Example (Migration Guide)

Here is an example of how you can migrate your existing logic using the new event callbacks.

Before

// Old way: Using onSelect and onDragSelect
patchmap.stateManager.setState('selection', {
  draggable: true,
  filter: (obj) => obj.type !== 'relations',
  onSelect: (obj, event) => {
    // It was difficult to distinguish between click and double-click.
    console.log('Selected:', obj);
    if (patchmap.transformer) {
      patchmap.transformer.elements = obj;
    }
  },
  onDragSelect: (objs, event) => {
    // It was difficult to run logic only when the drag finished.
    console.log('Drag Selected:', objs);
    if (patchmap.transformer) {
      patchmap.transformer.elements = objs;
    }
  },
});

After

// New way: Using onClick, onDoubleClick, and onDragEnd
patchmap.stateManager.setState('selection', {
  draggable: true,
  filter: (obj) => obj.type !== 'relations',

  // Confirm selection on 'click' completion.
  onClick: (target, event) => {
    console.log('Clicked:', target?.id);
    if (patchmap.transformer) {
      patchmap.transformer.elements = target ? [target] : [];
    }
  },

  // Perform a different action on 'double-click'. (onClick will not be called in this case)
  onDoubleClick: (target, event) => {
    console.log('Double Clicked:', target?.id);
    // e.g., patchmap.stateManager.setState('textEdit', target);
  },

  // Confirm the final selection when the drag ends.
  onDragEnd: (selected, event) => {
    console.log('Drag Selected:', selected.map(s => s.id));
    if (patchmap.transformer) {
      patchmap.transformer.elements = selected;
    }
  },
});

@gemini-code-assist
Copy link

Summary of Changes

Hello @MinCrohn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a major refinement to the SelectionState event model, moving towards a more granular and intuitive approach for handling user interactions. By replacing broad callbacks like onSelect and onDragSelect with a suite of specialized events, developers can now precisely differentiate between actions such as single clicks, double clicks, and various stages of drag operations. This change aims to simplify the implementation of complex interactive behaviors and improve the overall clarity of event handling within the system.

Highlights

  • Refined Event Model: The SelectionState event model has been significantly refined, replacing the generic onSelect and onDragSelect callbacks with a more granular set of events to better distinguish user intents.
  • New Event Callbacks: Introduced new, specific event callbacks including onDown, onUp, onClick, onDoubleClick, onDragStart, onDrag, onDragEnd, and onOver for more precise interaction handling.
  • Breaking Changes: The previous onSelect and onDragSelect callbacks have been removed, requiring users to migrate to the new, more specific event handlers.
  • Documentation Updates: Both English and Korean README files have been updated to reflect the new event model, including usage examples and a migration guide.
  • Dependency Updates: Various development dependencies, including Biome.js, commitlint, Rollup, Vitest, Playwright, and TypeScript, have been updated to their latest versions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant and well-designed refinement to the SelectionState event model. By replacing the broad onSelect and onDragSelect callbacks with a more granular set of events like onClick, onDoubleClick, and onDragEnd, it provides developers with much clearer and more intuitive control over user interactions. The implementation in SelectionState.js is solid, and the accompanying test updates correctly validate the new behavior.

My review includes suggestions to improve the documentation examples in README.md and README_KR.md to ensure they are consistent with the new API's best practices, particularly regarding the use of onDragEnd instead of onDrag for final selection and ensuring transformer.elements is always assigned an array. These changes will help users migrate smoothly to the new event model.

Overall, this is an excellent enhancement that greatly improves the usability of the selection state.

@MinCrohn
Copy link
Collaborator Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant and well-thought-out refinement of the SelectionState event model. The move from onSelect and onDragSelect to a more granular set of event callbacks like onClick, onDoubleClick, and onDragEnd is a great improvement for the library's usability and clarity. The implementation is solid, and the accompanying updates to documentation and tests are thorough. I've identified one minor inconsistency in the onUp event handler and provided a suggestion to align its behavior with the rest of the new event model.

@MinCrohn MinCrohn merged commit ab30b11 into main Nov 13, 2025
@MinCrohn MinCrohn deleted the fix/selection-state-event-callback branch November 13, 2025 03:55
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.

2 participants