jsoo-code-mirror#
Very, very incomplete
Some bindings using brr to code-mirror 6.
For self-hosted knots, clone URLs may differ based on your setup.
Download tar.gz
Three fixes for "Position N is out of range for changeset" errors:
1. js_top_worker: clamp output_at loc to input length — the ";;"
appended for parsing made pos_cnum extend past the original source
2. x-ocaml/editor: clamp decoration positions against CM document
length (Text.length) not OCaml String.length — they differ for
non-ASCII text (UTF-16 vs bytes). Also combine doc replacement +
decoration clear into a single transaction in set_source, and
read actual CM doc in build_range_set
3. jsoo-code-mirror/decoration: defensive safe_map that catches
JS RangeError in RangeSet.map and returns empty
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The Compartment+reconfigure approach caused "Position out of range for
changeset" RangeErrors because decorations weren't mapped through
document change transactions. A StateField maps decorations via
RangeSet.map(tr.changes) synchronously within each transaction,
keeping positions consistent with the document state.
- Add StateEffect and StateField OCaml bindings to jsoo-code-mirror
- Add Decoration.Range_set.empty and .map
- Convert editor.ml messages from Compartment to StateField+StateEffect
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The previous commit added StateField/StateEffect to includes.js but
didn't rebuild bundle.js (the esbuild+babel output that dune embeds).
Without this, the __CM__StateField and __CM__StateEffect globals were
undefined at runtime, causing TypeError on page load.
Built with: dune build --profile=with-bundle
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This reverts commit 051c718e8b619909d2f4199f6b5fbcd0642c5364.
Very, very incomplete
Some bindings using brr to code-mirror 6.