This repository was archived by the owner on Nov 12, 2026. It is now read-only.
Repository navigation
feat(core): every change to the text as twig's edit ops, for a host to send on - #25
Merged
Merged
Conversation
twig now refuses a bare attribute key in insert_directive (twig d4bcd44): no format reads one back as written, as djot does not read `{wide}` as an attribute at all and Markdown reads it back as `wide=""`. Doc::insert_directive already wrote a bare attribute as `key=""` for djot; it now does so for every format, so a `None` value keeps working. leaf-ffi and leaf-wasm pass an empty value through as `Some("")` rather than turning it into a bare key, and their docs, the Swift and TypeScript docs and the tests say `key=""`. twig also refuses a value holding a quote, so the round-trip test no longer writes one.
Behavioural-change: insert_directive writes a bare attribute, or an empty
value through leaf-ffi and leaf-wasm, as `key=""` in Markdown, where it
wrote `{key}`. Both read back as an empty value.
… released diaryx-org/twig#18 makes every twig edit retain, insert and delete ops, applied with one reparse and read back with Editor::last_ops. leaf takes the twig crates from that branch by git until it ships as twig 7, and goes back to a crates.io version then. Until then leaf-core cannot be published to crates.io, which takes no git dependency.
…o send on Doc::take_ops hands a host every change since it last asked, as one list of twig retain, insert and delete ops against the text it last took: what a host sends instead of the whole body, and what a replica holding the same text applies with twig::Op::apply. refresh, the funnel every change comes through, folds in twig's last_ops for each edit, so a gesture is the fewest ops that make it (bold over a word is two inserts and the word kept) and a keystroke is the span typed. Where more than one edit landed between refreshes, or the editor is a new one, the change is twig's diff of the two texts. replace_source applies twig's diff of the two texts as one edit instead of the one span between their common prefix and suffix, and carries the caret and selection through every place that changed. A caret between two changes far apart stays on its text; it used to fall inside the one span and go to its end. A reload applies the diff the same way, and keeps its caret rule. This is the part of leaf's task 9 in "An edit format shared by leaf and the core" that needs no event graph: the ops a local edit makes, out. Taking another replica's ops in while local ones are in flight needs the Eg-walker merge crate. Behavioural-change: replace_source leaves a caret or selection that lies between two changed places on its own text. It used to move one inside the span from the first change to the last to that span's end.
twig 7.0.0 ships the edit ops leaf#25 was built on, so leaf goes back from the PR branch to a crates.io version, and every lockfile that reaches twig takes 7.0.0. twig 7's Op::compose takes the text its first op list reads; Doc passes the text the host last took.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Takes twig's edit ops (diaryx-org/twig#18) into leaf. This is the part of task 9 in An edit format shared by leaf and the core (#23) that needs no event graph: the ops a local edit makes, out.
What changes
Doc::take_ops()/Doc::has_ops(). Every change since the host last asked, as one list of twigOps (retain, insert, delete) against the text it last took. A host sends this where it sent the whole body, and a replica holding the same text applies it withtwig::Op::apply.refresh, the funnel every change comes through, folds in twig'slast_opsfor each edit. A gesture is the fewest ops that make it: bold over a word is two inserts with the word kept. A keystroke is the span typed.replace_sourceand reload are changes like any other.replace_sourcethrough ops. It applies twig's diff of the two texts as one edit, not the one span between their common prefix and suffix, and carries the caret and selection through every place that changed. A caret between two changes far apart now stays on its text; it used to fall inside the one span and go to its end. Still one undo step.Reload through ops. A reload applies the diff the same way, so the host's ops and the undo step are the change and not the whole file. Its caret rule (keep the offset, clamped) is unchanged, since leaf-tui and leaf-core pin it in tests.
Taking twig after 6.0.0
The twig crates come from the twig PR's branch by git, until it ships as twig 7. All five lockfiles are updated, and they change only the twig entries. Until twig 7 is on crates.io, leaf-core cannot be published, because crates.io takes no git dependency.
Twig
mainalso carries an unreleased change (d4bcd44) that refuses a bare directive attribute key and a value holding a quote. So the first commit makesDoc::insert_directivewrite a bare attribute askey=""in every format, as it already did for djot. leaf-ffi and leaf-wasm now pass an empty value through instead of turning it into a bare key; without that, every Swift or web catalogue item with a flag would fail. Docs and tests in Rust, Swift and TypeScript now saykey="". The generated Swift binding's doc comment is edited to match what regenerating it would give.Behavioural changes (trailers on the commits)
insert_directivewrites a bare attribute, or an empty value through leaf-ffi and leaf-wasm, askey=""in Markdown, where it wrote{key}. Both read back as an empty value.replace_sourceleaves a caret or selection that lies between two changed places on its own text.Not in this PR
replace_source, as now.Testing
cargo test --workspace --exclude xtask --no-fail-fast: all green.crates/leaf-core/src/doc/tests/ops.rs:replace_sourcecarrying a selection between two changes;cargo fmt --all --checkis clean.