Skip to content

feat(editors): support onKeyboardEvent & enableKeyboardShortcuts in sub-editors (#837)#840

Merged
hm21 merged 1 commit into
stablefrom
fix/837-subeditor-keyboard-shortcuts
Jun 27, 2026
Merged

feat(editors): support onKeyboardEvent & enableKeyboardShortcuts in sub-editors (#837)#840
hm21 merged 1 commit into
stablefrom
fix/837-subeditor-keyboard-shortcuts

Conversation

@hm21

@hm21 hm21 commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Fixes #837

Problem

MainEditorCallbacks.onKeyboardEvent and MainEditorConfigs.enableKeyboardShortcuts only affected the main editor. In sub-editors there was no way to intercept or disable keyboard shortcuts — e.g. the R/F keys in the crop-rotate editor always triggered rotate/flip and onKeyboardEvent was never called.

Changes

Shared callback (onKeyboardEvent)

  • Moved onKeyboardEvent into the shared StandaloneEditorCallbacks base (plus a handleKeyboardEvent helper). Every standalone editor's callbacks (crop-rotate, paint, filter, tune, blur) now exposes it, and MainEditorCallbacks inherits it (no behavior change for the main editor).

Centralized handling (StandaloneEditorState)

  • The mixin now registers a single keyboard handler that:
    1. returns early when enableKeyboardShortcuts is false,
    2. forwards the event to the editor's onKeyboardEvent (consumes it when that returns true),
    3. otherwise delegates to an overridable onCustomKeyEvent hook for built-in shortcuts.

Per-editor wiring

  • Crop-rotate & paint: built-in shortcuts moved into onCustomKeyEvent; their own addHandler/removeHandler registration was removed; new enableKeyboardShortcuts config option added (default true).
  • Filter, tune, blur: forward keyboard events to their callbacks (they have no built-in shortcuts).

Usage

ProImageEditorConfigs(
  cropRotateEditor: CropRotateEditorConfigs(
    enableKeyboardShortcuts: false, // disable R/F/arrows/zoom shortcuts
  ),
)

ProImageEditorCallbacks(
  cropRotateEditorCallbacks: CropRotateEditorCallbacks(
    onKeyboardEvent: (event) {
      if (event.logicalKey == LogicalKeyboardKey.keyR) return true; // consume
      return false;
    },
  ),
)

Tests

Added a Keyboard shortcuts group to the crop-rotate editor tests: R rotates by default, enableKeyboardShortcuts: false ignores it, and an onKeyboardEvent returning true consumes it (no rotation). Full suite (431 tests) passes and dart analyze lib is clean.

…ub-editors (#837)

Keyboard handling previously only worked in the main editor: the
`onKeyboardEvent` callback and `enableKeyboardShortcuts` option had no
effect in sub-editors, so the crop-rotate `R`/`F` shortcuts could not be
intercepted or disabled.

- Move `onKeyboardEvent` into the shared `StandaloneEditorCallbacks` base
  (with a `handleKeyboardEvent` helper) so every standalone editor exposes
  it; `MainEditorCallbacks` now inherits it.
- Centralize keyboard handling in `StandaloneEditorState`: it registers a
  single handler that respects `enableKeyboardShortcuts`, forwards to the
  editor's `onKeyboardEvent` and otherwise delegates to an overridable
  `onCustomKeyEvent` hook.
- Crop-rotate and paint editors use the hook for their built-in shortcuts
  and expose a new `enableKeyboardShortcuts` config option (default true).
- Filter, tune and blur editors forward keyboard events to their callbacks.
@hm21 hm21 merged commit fc3a398 into stable Jun 27, 2026
1 check passed
@hm21 hm21 deleted the fix/837-subeditor-keyboard-shortcuts branch June 27, 2026 14:45
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.

[Bug]: onKeyboardEvent or enableKeyboardShortcuts not working for me in sub-editor

1 participant