Read code as literal text, and put its panel on the theme - #2
Conversation
An identifier like `default_line_height` came out italic with its underscores hidden: the inline rules ran over the raw line, so every underscore between backticks looked like an emphasis marker. Collect the code spans first and drop any markup whose markers land inside one. Matching on the markers rather than the whole span keeps emphasis that merely wraps code, as in **bold with `code` inside**, intact. Underscores now also need a word boundary to open emphasis, the way CommonMark and GitHub read them, so snake_case_name is left alone in prose too. Asterisks still delimit anywhere, and Ctrl+B and Ctrl+I insert asterisks, so nothing changes for the toolbar. Both fixes live in inlineMarkup, the source the editor shares through Backend::hiddenRangesAt, so the caret stops skipping over underscores it should never have hidden. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Everything between a pair of ``` fences is literal, but the highlighter had no memory of where it stood, so a code block was read as prose: snake_case_name came out italic with its underscores hidden, and a comment opening a line was set as a bold heading. The editor already counted fences for smartReturn, so it knew what the highlighter did not. Carry the state from block to block instead. Inside a fence nothing is markup and no markers are hidden; the code sits on the same panel inline code gets, and the fences themselves recede the way a heading's `#` does. The state lives on the block, which is how Backend::hiddenRangesAt learns to stop skipping the caret over underscores in code. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Inline code and fenced blocks sat on a hardcoded #1c1a1a, a warm grey left over from before the editor followed the desktop. On the current theme it read as a smudge against a green page while every colour around it tracked the theme. Omarchy themes name a lighter background for panels exactly like this one, so use the shade the theme chose. Not every theme sets the key, and a few set it to the page background, which would leave code with no panel at all; those fall back to a shade mixed from the page towards the text. Mixing rather than lightening keeps the shade moving on a pure black background, and lands on the theme's own hue either way. Backend resolves the colour and publishes it, the way it already does for the page and the accent, so the highlighter is handed a colour to paint rather than a theme to interpret. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Reviewed both halves against the source and on a disposable VM. The theme half holds up under the checks I had doubts about. Three small things:
Unterminated fences behave correctly: every remaining block stays Heads up that PRs #5, #8, #15 and #17 all touch |
Identifiers with underscores were being mangled in the editor. Between
backticks,
default_line_heightcame out italic with its underscores hidden,and the caret skipped over them as though they were markup — the inline rules
ran over the raw line and never noticed the code span. Fenced blocks had the
same problem for a different reason: the highlighter had no memory of being
inside one, so a code block was read as prose.
Before:

After:

Three changes: inline code is read as literal text; underscores now need a word
boundary to open emphasis, the way CommonMark and GitHub read them, so
snake_case_namesurvives in plain prose too; and fenced blocks are left aloneend to end. Asterisks still delimit anywhere, and Ctrl+B / Ctrl+I insert
asterisks, so the toolbar is unaffected. While in there, the panel code sits on
was a hardcoded
#1c1a1athat clashed with every theme — it now takes thelighter background the Omarchy theme names, falling back to a shade mixed from
the page for the themes that omit it or set it equal to the background.
One deliberate rough edge: the panel is painted per character, so a fenced
block's right edge steps with line length and a blank line inside a block gets
no panel at all. A continuous one needs either a block format the highlighter
can't set or a rectangle layer in QML, and neither seemed worth it here.
Test plan
bin/testpasses (16 tests)a character at a time instead of jumping
_italic_,*italic*,**bold**,__bold__,Ctrl+B and Ctrl+I
snake_case_namein prose is left alone#comment on its own lineinside a block is not set as a heading
Verified by hand on osaka-jade (dark) and in light mode.
🤖 Generated with Claude Code