Skip to content

feat(ui): Cooklang toolbar above the recipe editor #537

Closed

Description

@LeMyst

Goal

Add a toolbar above the editor (#editor-container in templates/edit.html) that gives one-click access to the Cooklang elements. Each button inserts the syntax, or wraps the current selection in it, so users don't have to remember the markup.

This is the first of two steps. The second one (a menu mode with a recipe picker, plus "New menu") builds on this toolbar.

Buttons (recipe mode)

Button No selection With selection x
Ingredient @{}, cursor after @ @x{}, cursor inside {}
Cookware #{} #x{}
Timer ~{%minutes}, cursor on the quantity ~x{%minutes}
Section new line == Section ==, name selected == x ==
Note prefix the current line(s) with > same
Comment toggle -- on the current line(s) same; [- x -] when the selection is inside a line
Metadata no frontmatter: insert ---\ntitle: \n---\n at the top; otherwise add a new key line at the end of the frontmatter —

Implementation notes

  • New static/js/src/toolbar.js with plain CodeMirror transactions (wrapSelection, prefixLines, insertBlock, ensureFrontmatter) built on view.state.changeByRange. Each action is one undo step, and the editor gets focus back after it runs.
  • Expose them on the existing window.CooklangEditor object in static/js/src/editor.js, like setDiagnostics. The bundle stays the single build-js entry.
  • templates/edit.html: add a <div role="toolbar" aria-label="…"> of .btn-sm / .icon-btn buttons between the header bar and the editor. Put data-mode="recipe" on it so a menu group can be added later. Follow the ARIA toolbar pattern (roving tabindex, arrow keys), and give every button a title and an aria-label.
  • Add an .editor-toolbar component to static/css/components.css using the existing tokens. It wraps at phone width, with no horizontal page scroll.
  • i18n: add editor-toolbar-* keys to locales/en-US/common.ftl and fr-FR; other locales fall back to en-US.
  • Out of scope: the editor status text that is still hardcoded English.

Tests

  • Playwright tests/e2e/editor-toolbar.spec.ts: open /edit/Neapolitan Pizza.cook, select text, click each button and check the document text. Intercept PUT /api/recipes/** with page.route, or the 1 s autosave will rewrite the seed fixtures.
  • Accessibility: the toolbar has its role and labels and can be reached from the keyboard.

Acceptance criteria

  • Every button works both with and without a selection.
  • Each action is a single undo step.
  • Works in light and dark themes and at phone width.
  • cargo fmt, cargo clippy, cargo test and npm test pass.

Activity

  1. added a commit that references this issue on Sep 25, 2026
    daebdaa
  2. added a commit that references this issue on Sep 27, 2026
    b6f77c9
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

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions