Repository navigation
Closed
Description
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.jswith plain CodeMirror transactions (wrapSelection,prefixLines,insertBlock,ensureFrontmatter) built onview.state.changeByRange. Each action is one undo step, and the editor gets focus back after it runs. - Expose them on the existing
window.CooklangEditorobject instatic/js/src/editor.js, likesetDiagnostics. The bundle stays the singlebuild-jsentry. templates/edit.html: add a<div role="toolbar" aria-label="…">of.btn-sm/.icon-btnbuttons between the header bar and the editor. Putdata-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 atitleand anaria-label.- Add an
.editor-toolbarcomponent tostatic/css/components.cssusing the existing tokens. It wraps at phone width, with no horizontal page scroll. - i18n: add
editor-toolbar-*keys tolocales/en-US/common.ftlandfr-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. InterceptPUT /api/recipes/**withpage.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 testandnpm testpass.
Metadata
Metadata
Assignees
Labels
No labels
Activity
feat(ui): Cooklang toolbar above the recipe editor
feat(ui): Cooklang toolbar above the recipe editor (cooklang#540)