feat(ui): syntax highlighting in the code editor - #24
Merged
Conversation
Add highlight_to_html() (plus the token_to_html and escape_html helpers) so the code editor can overlay syntax-colored text behind a transparent-text textarea. Pure string building - no web-sys or Leptos types, unit-tested on any host.
New CodeEditor component: a transparent-text textarea over a pre layer whose innerHTML comes from highlighter::highlight_to_html. Both panels (main + split) now mirror the selected syntax theme - the editor background and caret use the theme palette, scroll syncs between layers, and Tab still inserts spaces.
The editor wrapper carries the theme palette as background and the caret uses the theme foreground, so the input mirrors the export. The pre overlay and the transparent-text textarea share identical font metrics and wrapping (pre-wrap, break-all) and the pre layer scrolls in lockstep with the textarea.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The reactive prop:value binding rewrote the textarea on every input, stomping the browser's caret during paste/undo. Set the value once at creation and let the DOM own it - the signal now only follows input events. Tab insertion also switches from manual UTF-16 byte slicing (which panicked on multi-byte characters like the em dash in the sample code) to the native setRangeText().
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.
What
Adds live syntax highlighting to the code input(s) in the sidebar — the textarea is now overlaid on a
<pre>rendered from the samesyntecttoken stream that drives the canvas export, so what you type matches what you export.Branch note: stacked on
feat/sidebar-redesign(#23). Once #23 merges, GitHub retargets this PR tomainautomatically.How it works
highlighter::highlight_to_html()renders tokens as inline-HTML<span>s (color + weight/style/underline from the theme)CodeEditorcomponent (neweditor.rs): transparent-text textarea over apointer-events: none<pre>; both layers share identical font metrics and wrapping; the<pre>scrolls in lockstep with the textareaVerified in headless Chrome (CDP probe)
fnpink under Dracula; wrapper bgrgb(40,42,54), caretrgb(248,248,242)pre-wrap/break-allCommits
feat(highlighter): render token streams as inline-HTML spans—highlight_to_html,token_to_html,escape_html+ 8 new testsfeat(app): add syntax-highlighted code editor overlay—CodeEditorcomponent, wired into both panelsfeat(ui): style the highlighted code editor overlay—style.cssdocs: document the highlighted code editor overlay pattern—docs/DESIGN.mdVerification
cargo check -p codeframe-app --target wasm32-unknown-unknownpassescargo fmt --all --checkpassescargo clippy --workspace --all-targets -- -D warningspassescargo test --workspacepasses (43 tests incl. 8 new)trunk build --releasesucceeds