GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Manage the key handling as a graph plugin · Issue #1323 · maxGraph/maxGraph

Manage the key handling as a graph plugin #1323

New issue
Copy link
New issue
Copy link
Open
Enhancement
Open
Manage the key handling as a graph plugin#1323
Enhancement
Copy link

Description

@redfish4ktc
redfish4ktc
opened on Nov 16, 2026
Issue body actions

Is your feature request related to a problem? Please describe.

KeyHandler is a standalone object: it is created with new KeyHandler(graph), and the graph knows nothing about it.

This is fine when the handler is created to bind keys, since the instance is then stored and configured. But a KeyHandler is also needed without any key binding: it is the only caller of AbstractGraph.escape, so it is what makes the Escape key cancel the gesture in progress (moving cells, creating a connection, resizing a cell). To get this default behavior, applications and stories create an instance that they do not even store:

new KeyHandler(graph);

This code looks useless. Static analysis reports it (SonarCloud rule S1848 "useless object instantiation"), and the instances of the Storybook stories were about to be removed for this reason, see #910. RubberBandHandler had the same problem before it became a plugin: it was also instantiated without being stored.

Independently of how it is instantiated, the lifecycle of the handler is left to the application. The handler installs a keydown listener on the document element, which KeyHandler.onDestroy removes, but AbstractGraph.destroy does not call it, since the graph does not know the handler. So the application has to keep each instance somewhere, only to remember to destroy it along with the graph, and there is no way to retrieve the instance from the graph, for instance to bind a key in another part of the application.

Describe the solution you'd like

Provide the key handling as a graph plugin, so that the graph is the single place managing it:

  • the graph creates it when the plugin is registered, so getting the Escape handling no longer needs an instance created on its own;
  • the graph destroys it, through GraphPlugin.onDestroy, so the document listener is removed with the graph without the application keeping the instance;
  • the instance can be retrieved at any time with graph.getPlugin(...), to bind keys.

The plugin is not meant to be part of the default plugins of Graph: no KeyHandler is created by default today, and RubberBandHandler was not added to the default plugins either when it became a plugin. An application opts in by adding the plugin to the plugins option of the graph.

To decide at implementation time:

  • whether KeyHandler itself becomes the plugin, or a new plugin class extends or wraps the current implementation;
  • how to configure it, for instance its event target, which probably needs the configuration of plugins at graph construction time, see Configure plugins at graph construction time #1149;
  • how EditorKeyHandler, which creates its own KeyHandler, uses the plugin.

KeyHandler reads the deprecated KeyboardEvent.keyCode. A handler based on KeyboardEvent.key is planned in #1317, so the name and the id of the plugin should leave room for that new implementation, rather than tie the plugin to the current KeyHandler class.

Describe alternatives you've considered

  • Keep the standalone class and document why an instance without key binding is needed. This is the current state, see the JSDoc of KeyHandler: it explains the code, but keeps the unstored instance, the static analysis warning, and leaves the destruction of the handler to the application.
  • Store the instance in a variable that is never used. It does not make the intent clearer, and the application still has to destroy the handler itself.

Additional context

  • KeyHandler does not work in Storybook stories #910: the Storybook stories create such instances, and the Escape key only reaches them when the graph container has the focus.
  • Configure plugins at graph construction time #1149: configure plugins at graph construction time.
  • Provide a key handler based on KeyboardEvent.key instead of the deprecated keyCode #1317: key handler based on KeyboardEvent.key.

Activity

  1. redfish4ktc
    added the
    Enhancement
    issue type on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.