// fixtures/autoformat.mjs — typing "- " makes a bullet. // // Input rules: a pattern that matches the text just typed at the end of // a textblock, and a transformation applied when it does. Everything // here is the same shape a person has met in every editor since // Markdown, which is the whole argument for the specific set — these // are not chosen for expressiveness, they are chosen for being the ones // muscle memory already produces. // // UNDO IS THE FEATURE, not a nicety attached to it. An autoformat rule // that cannot be taken back is worse than no rule at all: it turns a // line that begins "- " into a list a person has to fight, and the // fighting happens at the exact moment they were mid-sentence. // undoInputRule, bound to Backspace immediately after a rule fires, // reverts the transformation and leaves the characters that were typed // — so "- " stays "- " and nothing was lost. It must be bound BEFORE // baseKeymap, whose own Backspace binding would otherwise delete a // character and never give the rule a chance; editor-entry.js's keymap // block already exists for exactly this ordering reason (see its // Shift-Enter comment). // // One interaction worth stating rather than assuming. This editor's // undo is y-prosemirror's Yjs UndoManager, not prosemirror-history — // buildCommands' comment in toolbar.mjs records what confusing the two // already cost once. undoInputRule is written against ProseMirror's own // plugin state, not against the history, so it works here — and // autoformat.test.mjs pins that much: the rule fires, Backspace reverts // it, and the typed characters come back. // // WHAT IS NOT TESTED, said plainly because an earlier version of this // comment claimed it was: the rule and its revert are two separate Yjs // edits, so Ctrl+Z after a Backspace-revert should re-apply the list // rather than continue backwards. That is believed, not asserted — // exercising it needs a live ySyncPlugin over a real Y.Doc, which none // of the DOM-free tests here set up. The spec named this interaction as // one of its five most likely failures and asked for a test; the test // does not exist, and saying so is better than a comment asserting it // does. import { inputRules, wrappingInputRule, textblockTypeInputRule } from 'prosemirror-inputrules' // The three bullet openers, matching what every editor accepts. The // leading \s* lets a rule fire on an already-indented line. const BULLET = /^\s*([-+*])\s$/ // A numbered list. // // The order attribute is DELIBERATELY NOT SET, and this is the one rule // here that departs from prosemirror-schema-list's own example. That // example passes the typed number through as `order`, so typing "7. " // gives a list starting at 7 — and it would be right to, except that // core/src/fragment.rs does not read `order` today: it renders every // ordered list as a plain