Skip to content

[STT-1586] - Replace hardcoded editor shortcuts with configurable custom editor controls#5117

Open
BrianMwangi21 wants to merge 19 commits intosuperdesk:developfrom
BrianMwangi21:STT-1586
Open

[STT-1586] - Replace hardcoded editor shortcuts with configurable custom editor controls#5117
BrianMwangi21 wants to merge 19 commits intosuperdesk:developfrom
BrianMwangi21:STT-1586

Conversation

@BrianMwangi21
Copy link
Copy Markdown
Contributor

@BrianMwangi21 BrianMwangi21 commented Mar 25, 2026

Purpose

As part of adding the thin space and ndash to the toolbar, this PR implement a config-driven custom editor features engine to replace hardcoded keyboard shortcuts and styling in the editor3 system. This allows different Superdesk clients to define their own custom editor features without modifying client-core code.

What has changed

  • New CustomEditorControls which is a central registry for custom editor features that reads from appConfig.authoring.customEditorFeatures
  • Removed hardcoded shortcuts: All hardcoded keyboard shortcuts for company/person tags and ndash/thin-space removed and now defined in the config for STT.
  • Updated superdesk-ui-framework: Bumped to 6.1.3 for new icons (n-dash, thin_space)

Steps to test

  1. Create a new article with a content type that has custom editor features enabled (e.g., pika)
  2. Toolbar buttons: Verify company tag, person tag, ndash, and thin space buttons appear in the toolbar
  3. Test existing and new Keyboard shortcuts or toolbar icons:
    • Ctrl/Cmd + 3 toggles company tag
    • Ctrl/Cmd + 6 toggles person tag
    • Ctrl/Cmd + Alt + - inserts ndash
    • Ctrl/Cmd + Alt + Shift + Space inserts thin space
  4. Save and reload: Apply styles/insertions, save article, reload - verify they persist

Screenshots

2026-03-25_17-30-20

Checklist

  • I reviewed my code
  • I tested all affected functionality and made sure it works

Resolves: STT-1586

- Add FeatureRegistry for dynamic feature registration
- Support configurable inline styles and character insertions
- Add cross-platform keyboard shortcuts using 'primary' modifier
- Remove hardcoded shortcuts from Editor3Component
- Update superdesk-ui-framework to 6.1.3 for new icons
- Add IShortcutConfig, ICustomInlineStyle, ICharacterInsertion interfaces
- Update format option naming: EDITOR_TAG_*, INSERT_CHAR_*
- Remove migrateLegacyConfig() from FeatureRegistry
- Remove shortcut property from customEditorTags type definition
- All clients must now use customEditorFeatures config
eos87 added 2 commits March 27, 2026 12:20
The previous reverse-map approach in normalizeCssTagSpans matched pasted spans against individual CSS property+value pairs and stopped at the first match. When FeatureRegistry.getStyleMap() started including display: inline-block in the style map, both COMPANY and PERSON tags shared that value. Since PERSON was registered last, its entry overwrote COMPANY's in the reverse map, causing all COMPANY tags to be misidentified as PERSON on paste.

Replace the single-property reverse lookup with full-fingerprint matching: for each pasted <span>, every CSS property in a registered style's fingerprint must match before that style is applied. Shared properties like display: inline-block no longer cause false positives because the discriminating property (borderBlockEnd) is always checked too.
@eos87 eos87 requested review from Copilot March 27, 2026 11:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a config-driven “custom editor features” engine for editor3 so clients can define custom inline styles and character insertions (e.g., thin space and n-dash) via appConfig.authoring.customEditorFeatures, replacing previously hardcoded shortcuts/styling.

Changes:

  • Added FeatureRegistry to register custom inline styles + character insertions (toolbar buttons + keyboard shortcuts) from config.
  • Updated editor3 toolbar, formatting-option plumbing, and key-command handling to use registered features.
  • Improved HTML paste parsing for custom tag detection by switching to full CSS “fingerprint” matching; updated tests accordingly.

Reviewed changes

Copilot reviewed 15 out of 17 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
scripts/core/superdesk-api.d.ts Adds type definitions for config-driven custom editor features and formatting-option identifiers.
scripts/core/editor3/reducers/editor3.tsx Adds a generic INSERT_CHARACTER reducer action for character insertion.
scripts/core/editor3/html/tests/from-html.spec.ts Updates/extends tests for CSS fingerprint-based custom tag detection.
scripts/core/editor3/html/from-html/index.ts Reworks custom tag normalization to match full CSS fingerprints (multiple properties).
scripts/core/editor3/helpers/inlineStyles.ts Sources custom inline styles from FeatureRegistry instead of hardcoded tag config.
scripts/core/editor3/get-formatting-options-for-table.tsx Ensures dynamic feature formatting options are allowed in table-like blocks where relevant.
scripts/core/editor3/components/toolbar/index.tsx Renders character-insertion toolbar buttons from FeatureRegistry; wires insert action.
scripts/core/editor3/components/toolbar/StyleButton.tsx Builds icons/tooltips for custom inline styles from FeatureRegistry.
scripts/core/editor3/components/toolbar/IconButton.tsx Changes event handling to use onMouseDown (preventing default) for toolbar icon clicks.
scripts/core/editor3/components/tests/editor3.spec.tsx Updates keyboard shortcut tests to use config-driven commands/options.
scripts/core/editor3/components/customStyleMap.tsx Gets custom tag style map from FeatureRegistry instead of old tag config.
scripts/core/editor3/components/Editor3Component.tsx Replaces hardcoded shortcut logic with FeatureRegistry matching and feature-based commands.
scripts/core/editor3/actions/editor3.tsx Adds insertCharacter (and wrappers) action creators.
scripts/core/editor3/FeatureRegistry.ts New registry that reads config, registers features, matches shortcuts, and formats shortcut display.
scripts/apps/workspace/content/components/get-content-profiles-form-config.tsx Derives custom editor tags and formatting option labels from FeatureRegistry.
package.json Bumps superdesk-ui-framework to 6.1.3 (icons for n-dash / thin space).
package-lock.json Locks updated superdesk-ui-framework (and dependent lockfile updates).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@eos87 eos87 requested review from Copilot and removed request for Copilot March 27, 2026 13:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 17 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…ession fix

Adds runtime validation to CustomEditorControls: warns on duplicate format IDs, shortcut collisions, and missing
character insertions. Fixes keyboard shortcuts not firing on macOS when Alt/Option modifies e.key by falling back to
the physical key via nativeEvent.code (React 16 SyntheticKeyboardEvent does not expose e.code directly). Fixes backspace regression caused by an extra break statement preventing fall-through to RichUtils.handleKeyCommand. Shows "Option" instead of "Alt" in shortcut tooltips on macOS, and handles special key labels like Space and arrow keys. Removes the obsolete customEditorTags type from the API definition.
@eos87 eos87 changed the title [STT-1586] - As STT journalist I would like to have toolbar buttons for thin space and ndash [STT-1586] - Replace hardcoded editor shortcuts with configurable custom editor controls Mar 27, 2026
@eos87
Copy link
Copy Markdown
Contributor

eos87 commented Mar 27, 2026

Related to #5008

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 17 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants