fix(editor): stop markdown auto-format from firing inside code blocks #837

Merged
raisondetredev merged 1 commit from refs/pull/837/head into main 2026-08-11 19:13:25 +02:00
raisondetredev commented 2026-08-11 19:13:16 +02:00 (Migrated from codeberg.org)

Typing a Go generic signature into a code block lost text. The moment the
closing paren landed on func PlusOneHundred[T Integer](in T, AppFlowy's
markdown-link shortcut matched \[(...)\]\((...)\) and rewrote the run as
a hyperlink reading T Integer — brackets, parens and the parameter name
deleted, the remainder silently carrying an href of in T.

AppFlowy gates its slash menu on the cursor's block type but gives the
markdown shortcuts no such check, so every one of them fires anywhere
there is a delta. A code listing is verbatim text: `, *, _, ~
and their doubled forms, -- (so git log --oneline becomes an em dash)
and => all reinterpret code as markup, and the block-level conversions
are worse still — a listing whose first line opens # , - , > or
1. is retyped whole as a heading, bullet or quote.

halkyonCodeBlockAware wraps a shortcut so its handler stands down when
the caret is in a code block, returning false to hand the keystroke back
to the IME, which types the literal character. Outside code blocks the
wrapped handler runs untouched. _codeBlockSafe routes every stock event
through it, keeping the existing halkyonCodeAwareNewLine swap for Enter
and passing the other newline handlers through — those already gate on
their own block type. Applying it in halkyonCharacterShortcuts covers
every surface at once: flashcard faces, notes, path steps, PDF page notes.

The wrapper forwards regExp and handlerWithCharacter as well. Nothing
in appflowy_editor 6.2.0 sets either, but its own copyWith drops the
latter, and building the event explicitly avoids inheriting that on a
version bump.

Cards authored before this fix may already hold mangled text; repairing
those is a separate pass.

Signed-off-by: Tizian 「ティツィアーン」 raisondetredev@pm.me

Typing a Go generic signature into a code block lost text. The moment the closing paren landed on `func PlusOneHundred[T Integer](in T`, AppFlowy's markdown-link shortcut matched `\[(...)\]\((...)\)` and rewrote the run as a hyperlink reading `T Integer` — brackets, parens and the parameter name deleted, the remainder silently carrying an href of `in T`. AppFlowy gates its slash menu on the cursor's block type but gives the markdown shortcuts no such check, so every one of them fires anywhere there is a delta. A code listing is verbatim text: `` ` ``, `*`, `_`, `~` and their doubled forms, `--` (so `git log --oneline` becomes an em dash) and `=>` all reinterpret code as markup, and the block-level conversions are worse still — a listing whose first line opens `# `, `- `, `> ` or `1. ` is retyped whole as a heading, bullet or quote. `halkyonCodeBlockAware` wraps a shortcut so its handler stands down when the caret is in a code block, returning false to hand the keystroke back to the IME, which types the literal character. Outside code blocks the wrapped handler runs untouched. `_codeBlockSafe` routes every stock event through it, keeping the existing `halkyonCodeAwareNewLine` swap for Enter and passing the other newline handlers through — those already gate on their own block type. Applying it in `halkyonCharacterShortcuts` covers every surface at once: flashcard faces, notes, path steps, PDF page notes. The wrapper forwards `regExp` and `handlerWithCharacter` as well. Nothing in appflowy_editor 6.2.0 sets either, but its own `copyWith` drops the latter, and building the event explicitly avoids inheriting that on a version bump. Cards authored before this fix may already hold mangled text; repairing those is a separate pass. Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
project-halkyon/halkyon-learn!837
No description provided.