Skip to content

Conversation

@caio-pizzol
Copy link
Contributor

Add 'Create Field' action to the slash and context menus, enabling users to convert selected text into template fields.


Linear Issue: SD-541

Open in Cursor Open in Web

This commit introduces a new slash menu command to create fields from selected text. It also includes helper functions for sanitizing and ensuring unique field aliases.

Co-authored-by: caiopizzol <caiopizzol@gmail.com>
@cursor
Copy link

cursor bot commented Oct 9, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@linear
Copy link

linear bot commented Oct 9, 2025

SD-541 Add "Create Field" action to slash/context menu

Summary

Enable users to convert selected text into template fields via slash menu or right-click context menu

Tasks

  • Configure SuperDoc's slashMenu module with custom items in template builder initialization
  • Add "Create Field" menu item that shows only when text is selected (showWhen: context.hasSelection)
  • Implement action to convert selected text into a field using insertField with selected text as alias
  • Test both slash menu (/) and context menu (right-click) triggers
  • Handle edge cases (empty selection, duplicate field aliases, special characters in selection)
  • Consider exposing slashMenu configuration via component props for user customization

Notes

Integration approach: Add slashMenu module configuration to SuperDoc initialization in src/index.tsx, similar to how toolbar is configured

Menu item structure:

{
  id: 'create-field',
  label: 'Create Field',
  icon: '🏷️',
  showWhen: (context) => context.hasSelection,
  action: (editor, context) => {
    // Convert selected text to field
    insertFieldInternal('inline', {
      alias: context.selectedText,
      category: 'Custom'
    });
  }
}

User experience: When user selects text → types / or right-clicks → sees "Create Field" option → click converts selection to field

Edge cases:

  • Long selections (>50 chars) - truncate or warn
  • Duplicate field names - append suffix or prompt user
  • Special characters - sanitize or allow through

Future enhancement: Could add modal to set field category/metadata instead of always defaulting to 'Custom'

@caio-pizzol caio-pizzol closed this Oct 9, 2025
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