Repository navigation
Conversation
…S-recorded scripts/markdown-shortcuts vector
## Description
The Rust port had no markdown shortcuts: typing `# `, `- ` or `**bold**`
left the markdown as text. It also had no `KEY_ENTER_COMMAND`, which the
shortcuts' Enter handler listens on.
- `markdown::register_markdown_shortcuts` ports `MarkdownShortcuts.ts`.
An update listener runs the element, multiline element, text match and
text format transformers as markdown is typed. A `KEY_ENTER_COMMAND`
handler runs the code fence and the element transformers that trigger
on Enter. It honours the collaboration, historic and composition-end
tags, the typed-one-character check (`$getOffsetInParent`) and
`HISTORY_PUSH_TAG`.
- `KEY_ENTER_COMMAND` takes a `KeyboardEvent` (modifier keys and
`preventDefault`), or `None` for JS's `null`. Its JS handlers are
ported: `registerRichText`'s (with `$escapeFormatsForTrigger` on the
default triggers, and the block-decorator NodeSelection case),
`registerPlainText`'s, and `CodeExtension`'s `$exitCodeNodeOnEnter`
handler in `register_code`.
- `ops.ts` gets a `markdown` script flag
(`registerMarkdownShortcuts(editor, TRANSFORMERS)`) and
`KEY_ENTER_COMMAND`. The Rust and Swift script runners read both.
- `scripts/markdown-shortcuts` (15 cases) is recorded from JS. It covers
headings, quotes, lists, code fences on space and on Enter, inline
formats and links, what cancels them, several characters at once, the
composition-end, collaboration and historic tags, and undo. It also adds
one `KEY_ENTER_COMMAND` case each to `scripts/rich-text-commands`,
`scripts/plain-text` and `scripts/code`, leaving their existing cases
unchanged.
Swift matched JS on every new case, so no Swift source changes.
## Test plan
### Before
```
$ cargo run -p lexical-conformance -- scripts/
| `scripts/markdown-shortcuts` | – | – | – | – | – | not implemented |
```
### After
```
$ cargo run -p lexical-conformance
| `scripts/code` | 10 | 10 | 0 | 0 | 0 | pass |
| `scripts/markdown-shortcuts` | 15 | 15 | 0 | 0 | 0 | pass |
| `scripts/plain-text` | 5 | 5 | 0 | 0 | 0 | pass |
| `scripts/rich-text-commands` | 7 | 7 | 0 | 0 | 0 | pass |
| **Total** | 655 | 655 | 0 | 0 | 0 | |
$ swift test --filter ScriptTests # Linux, Swift 6.4.2
✔ Suite ScriptTests passed
$ pnpm exec vitest run src/scripts.test.ts # packages/lexical-conformance
Tests 19 passed (19)
```
`cargo fmt --all --check`, `cargo clippy --workspace --all-targets
--all-features --locked -- -D warnings`, `cargo test --workspace
--all-features --locked`, `RUSTDOCFLAGS='-D warnings' cargo doc
--workspace --all-features --no-deps --locked` and
`cargo +1.88 check -p lexical-editor --all-features --locked` pass.
Amp-Thread-ID: https://ampcode.com/threads/T-01a1daf1-150e-709b-aaed-996443a64459
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The Rust port had no markdown shortcuts: typing
#,-or**bold**left the markdown as text. It also had no
KEY_ENTER_COMMAND, which theshortcuts' Enter handler listens on.
markdown::register_markdown_shortcutsportsMarkdownShortcuts.ts.An update listener runs the element, multiline element, text match and
text format transformers as markdown is typed. A
KEY_ENTER_COMMANDhandler runs the code fence and the element transformers that trigger
on Enter. It honours the collaboration, historic and composition-end
tags, the typed-one-character check (
$getOffsetInParent) andHISTORY_PUSH_TAG.KEY_ENTER_COMMANDtakes aKeyboardEvent(modifier keys andpreventDefault), orNonefor JS'snull. Its JS handlers areported:
registerRichText's (with$escapeFormatsForTriggeron thedefault triggers, and the block-decorator NodeSelection case),
registerPlainText's, andCodeExtension's$exitCodeNodeOnEnterhandler in
register_code.ops.tsgets amarkdownscript flag(
registerMarkdownShortcuts(editor, TRANSFORMERS)) andKEY_ENTER_COMMAND. The Rust and Swift script runners read both.scripts/markdown-shortcuts(15 cases) is recorded from JS. It coversheadings, quotes, lists, code fences on space and on Enter, inline
formats and links, what cancels them, several characters at once, the
composition-end, collaboration and historic tags, and undo. It also adds
one
KEY_ENTER_COMMANDcase each toscripts/rich-text-commands,scripts/plain-textandscripts/code, leaving their existing casesunchanged.
Swift matched JS on every new case, so no Swift source changes.
Test plan
Before
After
cargo fmt --all --check,cargo clippy --workspace --all-targets --all-features --locked -- -D warnings,cargo test --workspace --all-features --locked,RUSTDOCFLAGS='-D warnings' cargo doc --workspace --all-features --no-deps --lockedandcargo +1.88 check -p lexical-editor --all-features --lockedpass.