From a4ced9498f912d031582221e99bf04b5a0e7d89e Mon Sep 17 00:00:00 2001 From: adammharris Date: Sat, 24 Oct 2026 18:57:35 +0000 Subject: [PATCH 1/5] fix(core): write a bare directive attribute as key="" in every format 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. --- crates/leaf-core/src/doc/presentation.rs | 30 +++++++++---------- .../leaf-core/src/doc/tests/presentation.rs | 13 ++++---- crates/leaf-ffi/src/lib.rs | 14 ++++----- crates/leaf-wasm/src/lib.rs | 13 ++++---- .../Sources/LeafUI/DirectiveItem.swift | 5 ++-- .../Sources/LeafUI/LeafEditorView.swift | 2 +- .../LeafUITests/DirectiveCatalogueTests.swift | 2 +- .../Sources/LeafFFI/leaf_ffi.swift | 8 ++--- packages/leaf-web/src/editor.d.ts | 2 +- 9 files changed, 41 insertions(+), 48 deletions(-) diff --git a/crates/leaf-core/src/doc/presentation.rs b/crates/leaf-core/src/doc/presentation.rs index feb8f2b1..d1708e79 100644 --- a/crates/leaf-core/src/doc/presentation.rs +++ b/crates/leaf-core/src/doc/presentation.rs @@ -160,10 +160,11 @@ impl Doc { /// the whole of the rule, including why a code block, a list item, a table /// and a setext heading are left unsplit. /// - /// `attrs` are `(key, value)` pairs in the order they are written, a `None` - /// value a bare attribute — the shape - /// [`DirectiveMark::attrs`](crate::wysiwyg::DirectiveMark::attrs) reads - /// back. + /// `attrs` are `(key, value)` pairs in the order they are written — the + /// shape [`DirectiveMark::attrs`](crate::wysiwyg::DirectiveMark::attrs) + /// reads back. A `None` value, a bare attribute, is written `key=""`: + /// twig refuses a bare key, which djot does not read as an attribute at + /// all and Markdown reads back as `key=""` regardless. /// /// Refused, with a status and nothing written, where /// [`Capabilities::directives`] is `false`, and for a `name` or `label` @@ -171,13 +172,10 @@ impl Doc { /// digits, `-` and `_`, and a label may hold no line end and no square /// bracket. twig is the judge of both, asked before anything is parted. /// - /// djot needs two things of its own, since its spelling is a fence under - /// an attribute line. A bare attribute is written `key=""`: twig writes - /// `{wide}`, which djot does not read as an attribute at all, and - /// Markdown reads its own `{wide}` back as `wide=""` regardless. And a - /// label is refused, because djot has nowhere to put one: twig writes it - /// as the fence's body, which reads back as a container holding a - /// paragraph and not as a directive. + /// djot refuses a label, because its spelling is a fence under an + /// attribute line and it has nowhere to put one: twig would write it as + /// the fence's body, which reads back as a container holding a paragraph + /// and not as a directive. pub fn insert_directive( &mut self, name: &str, @@ -185,8 +183,12 @@ impl Doc { attrs: &[(String, Option)], ) { let supported = self.capabilities().directives; + let attrs: Attrs = attrs + .iter() + .map(|(k, v)| (k.clone(), Some(v.clone().unwrap_or_default()))) + .collect(); if self.format != Format::Djot { - self.write_directive("directive", supported, name, label, attrs); + self.write_directive("directive", supported, name, label, &attrs); return; } if label.is_some_and(|l| !l.is_empty()) { @@ -195,10 +197,6 @@ impl Doc { } return; } - let attrs: Attrs = attrs - .iter() - .map(|(k, v)| (k.clone(), Some(v.clone().unwrap_or_default()))) - .collect(); self.write_directive("directive", supported, name, None, &attrs); } diff --git a/crates/leaf-core/src/doc/tests/presentation.rs b/crates/leaf-core/src/doc/tests/presentation.rs index aa66c84a..a22ef59e 100644 --- a/crates/leaf-core/src/doc/tests/presentation.rs +++ b/crates/leaf-core/src/doc/tests/presentation.rs @@ -619,7 +619,7 @@ fn insert_page_break_parts_the_paragraph_and_spells_the_directive() { fn insert_directive_round_trips_name_label_and_attrs() { let attrs: Attrs = vec![ ("src".into(), Some("https://x.org/a".into())), - ("title".into(), Some("a \"quoted\" b".into())), + ("title".into(), Some("a b".into())), ("wide".into(), None), ]; let mut md = doc_with("directive_md", "hello world\n"); @@ -628,7 +628,7 @@ fn insert_directive_round_trips_name_label_and_attrs() { assert_eq!(md.status, None); assert_eq!( md.source, - "hello\n\n::x-card[A card]{src=\"https://x.org/a\" title=\"a \\\"quoted\\\" b\" wide}\n\nworld\n" + "hello\n\n::x-card[A card]{src=\"https://x.org/a\" title=\"a b\" wide=\"\"}\n\nworld\n" ); assert!(md.dirty); md.view = View::Wysiwyg; @@ -638,21 +638,20 @@ fn insert_directive_round_trips_name_label_and_attrs() { }; assert_eq!(d.name, "x-card"); assert_eq!(d.label, "A card"); - // A bare attribute reads back with an empty value: that is what twig - // reports for Markdown's `{wide}`. + // A bare attribute is written `wide=""` and reads back empty. assert_eq!( d.key().attrs, [ ("src".to_string(), "https://x.org/a".to_string()), - ("title".to_string(), "a \"quoted\" b".to_string()), + ("title".to_string(), "a b".to_string()), ("wide".to_string(), String::new()), ] ); assert_eq!(d.attr("src"), Some("https://x.org/a")); // djot: the attributes on a line of their own over the fence, a bare - // one spelled `key=""` so that djot reads it as an attribute at all, - // and a class kept apart from the name the fence gives. + // one spelled `key=""` as in every format, and a class kept apart from + // the name the fence gives. let mut dj = fmt_doc("hello world\n", Format::Djot); dj.caret = 5; let dj_attrs: Attrs = vec![ diff --git a/crates/leaf-ffi/src/lib.rs b/crates/leaf-ffi/src/lib.rs index b79c9ba0..05f7ffa8 100644 --- a/crates/leaf-ffi/src/lib.rs +++ b/crates/leaf-ffi/src/lib.rs @@ -3400,8 +3400,8 @@ impl LeafDoc { /// [`insert_page_break`](Self::insert_page_break) places a page break, /// which is this gesture with leaf's own name. It arrives in /// [`DocView::directives`] as it went in: `attrs` is the - /// [`DirectiveAttr`] list a [`DirectiveView`] carries, an empty value a - /// bare attribute. + /// [`DirectiveAttr`] list a [`DirectiveView`] carries. An empty value is + /// written `key=""`, the flag every format reads back as one. /// /// A name twig will not write (it is an ASCII letter and then letters, /// digits, `-` and `_`), a label holding a line end or a square bracket, @@ -3414,10 +3414,8 @@ impl LeafDoc { label: Option, attrs: Vec, ) -> DocView { - let attrs: Vec<(String, Option)> = attrs - .into_iter() - .map(|a| (a.key, (!a.value.is_empty()).then_some(a.value))) - .collect(); + let attrs: Vec<(String, Option)> = + attrs.into_iter().map(|a| (a.key, Some(a.value))).collect(); let mut g = self.lock(); g.doc.insert_directive(&name, label.as_deref(), &attrs); g.frame() @@ -5247,7 +5245,7 @@ mod tests { } /// A host's directive goes in as the view hands it out — name, label and - /// the `DirectiveAttr` list, an empty value a bare attribute — and a + /// the `DirectiveAttr` list, an empty value written `key=""` — and a /// reported height reserves its rows under the same key. #[test] fn a_directive_goes_in_the_way_it_comes_out() { @@ -5265,7 +5263,7 @@ mod tests { let v = d.insert_directive("x-card".into(), Some("A card".into()), attrs); assert!( d.source() - .contains("::x-card[A card]{src=\"https://x.org/a\" wide}") + .contains("::x-card[A card]{src=\"https://x.org/a\" wide=\"\"}") ); let [x] = v.directives.as_slice() else { panic!("one directive"); diff --git a/crates/leaf-wasm/src/lib.rs b/crates/leaf-wasm/src/lib.rs index fad99d7a..5bdb7049 100644 --- a/crates/leaf-wasm/src/lib.rs +++ b/crates/leaf-wasm/src/lib.rs @@ -2371,7 +2371,8 @@ impl LeafDoc { /// — a host's catalogue item. Placed as `insert_page_break` places a page /// break, which is this gesture with leaf's own name. It arrives in /// `DocView.directives` as it went in: `attrs` is the [`DirectiveAttr`] - /// list a [`DirectiveView`] carries, an empty value a bare attribute. + /// list a [`DirectiveView`] carries. An empty value is written `key=""`, + /// the flag every format reads back as one. /// /// A name twig will not write (an ASCII letter and then letters, digits, /// `-` and `_`), a label holding a line end or a square bracket, a label in @@ -2383,10 +2384,8 @@ impl LeafDoc { label: Option, attrs: Vec, ) -> Result { - let attrs: Vec<(String, Option)> = attrs - .into_iter() - .map(|a| (a.key, (!a.value.is_empty()).then_some(a.value))) - .collect(); + let attrs: Vec<(String, Option)> = + attrs.into_iter().map(|a| (a.key, Some(a.value))).collect(); self.doc.insert_directive(&name, label.as_deref(), &attrs); self.frame() } @@ -4241,7 +4240,7 @@ mod tests { } /// A host's directive goes in as the view hands it out — name, label and - /// the `DirectiveAttr` list, an empty value a bare attribute — and a + /// the `DirectiveAttr` list, an empty value written `key=""` — and a /// reported height reserves its rows under the same key. #[test] fn a_directive_goes_in_the_way_it_comes_out() { @@ -4263,7 +4262,7 @@ mod tests { assert!( d.doc .source - .contains("::x-card[A card]{src=\"https://x.org/a\" wide}") + .contains("::x-card[A card]{src=\"https://x.org/a\" wide=\"\"}") ); let views = wysiwyg_directives(&d.doc.vmap); let [x] = views.as_slice() else { diff --git a/packages/leaf-swift/Sources/LeafUI/DirectiveItem.swift b/packages/leaf-swift/Sources/LeafUI/DirectiveItem.swift index 66f62bcd..cd413dfc 100644 --- a/packages/leaf-swift/Sources/LeafUI/DirectiveItem.swift +++ b/packages/leaf-swift/Sources/LeafUI/DirectiveItem.swift @@ -13,9 +13,8 @@ import Foundation import LeafFFI /// What one directive is written with: its `[label]` and its `{attributes}`. -/// An empty attribute value writes a bare attribute (`{wide}`), as an empty one -/// reads back — the `DirectiveAttr` list a `DirectiveView` hands out is the -/// list this takes. +/// An empty attribute value is written `wide=""`, and reads back empty — the +/// `DirectiveAttr` list a `DirectiveView` hands out is the list this takes. public struct DirectiveContent { /// The directive's `[label]`, or nil for none. djot has nowhere to put one /// and refuses the whole directive rather than dropping it. diff --git a/packages/leaf-swift/Sources/LeafUI/LeafEditorView.swift b/packages/leaf-swift/Sources/LeafUI/LeafEditorView.swift index d27f216d..cf18e80b 100644 --- a/packages/leaf-swift/Sources/LeafUI/LeafEditorView.swift +++ b/packages/leaf-swift/Sources/LeafUI/LeafEditorView.swift @@ -826,7 +826,7 @@ public final class LeafEditorModel { /// Write the leaf directive `name` at the caret, with `label` and `attrs`, /// placed as a page break is: a paragraph parts around it and the caret - /// lands on a line under it. An empty attribute value is a bare attribute. + /// lands on a line under it. An empty attribute value is written `key=""`. /// /// Writes nothing, with a status, where core refuses: a name that is not a /// letter and then letters, digits, `-` and `_`; a label holding a line end diff --git a/packages/leaf-swift/Tests/LeafUITests/DirectiveCatalogueTests.swift b/packages/leaf-swift/Tests/LeafUITests/DirectiveCatalogueTests.swift index 3af18c4e..8d4f90bc 100644 --- a/packages/leaf-swift/Tests/LeafUITests/DirectiveCatalogueTests.swift +++ b/packages/leaf-swift/Tests/LeafUITests/DirectiveCatalogueTests.swift @@ -36,7 +36,7 @@ final class DirectiveCatalogueTests: XCTestCase { let model = try LeafEditorModel(source: "Text.\n") model.insert(DirectiveItem(id: "d.embed", name: "embed", title: "Embed", icon: "link", content: DirectiveContent(attrs: ["src": "https://x.org", "wide": ""]))) - XCTAssertTrue(model.source().contains("::embed{src=\"https://x.org\" wide}"), model.source()) + XCTAssertTrue(model.source().contains("::embed{src=\"https://x.org\" wide=\"\"}"), model.source()) } func testAnAskCanWriteOrCancel() throws { diff --git a/packages/leaf-swift/uniffi-generated/Sources/LeafFFI/leaf_ffi.swift b/packages/leaf-swift/uniffi-generated/Sources/LeafFFI/leaf_ffi.swift index 5f7a4e18..99a6a558 100644 --- a/packages/leaf-swift/uniffi-generated/Sources/LeafFFI/leaf_ffi.swift +++ b/packages/leaf-swift/uniffi-generated/Sources/LeafFFI/leaf_ffi.swift @@ -1311,8 +1311,8 @@ public protocol LeafDocProtocol: AnyObject, Sendable { * [`insert_page_break`](Self::insert_page_break) places a page break, * which is this gesture with leaf's own name. It arrives in * [`DocView::directives`] as it went in: `attrs` is the - * [`DirectiveAttr`] list a [`DirectiveView`] carries, an empty value a - * bare attribute. + * [`DirectiveAttr`] list a [`DirectiveView`] carries. An empty value is + * written `key=""`, the flag every format reads back as one. * * A name twig will not write (it is an ASCII letter and then letters, * digits, `-` and `_`), a label holding a line end or a square bracket, @@ -2765,8 +2765,8 @@ open func insert(text: String) -> DocView { * [`insert_page_break`](Self::insert_page_break) places a page break, * which is this gesture with leaf's own name. It arrives in * [`DocView::directives`] as it went in: `attrs` is the - * [`DirectiveAttr`] list a [`DirectiveView`] carries, an empty value a - * bare attribute. + * [`DirectiveAttr`] list a [`DirectiveView`] carries. An empty value is + * written `key=""`, the flag every format reads back as one. * * A name twig will not write (it is an ASCII letter and then letters, * digits, `-` and `_`), a label holding a line end or a square bracket, diff --git a/packages/leaf-web/src/editor.d.ts b/packages/leaf-web/src/editor.d.ts index 2295325f..7e6ddf22 100644 --- a/packages/leaf-web/src/editor.d.ts +++ b/packages/leaf-web/src/editor.d.ts @@ -456,7 +456,7 @@ export interface RegionEditor { /** * A directive's attributes as `insertDirective` takes them: the `{key, value}` - * list a `DirectiveView` carries — an empty value is a bare attribute — or a + * list a `DirectiveView` carries — an empty value is written `key=""` — or a * plain object of the same pairs. */ export type DirectiveAttrs = DirectiveAttr[] | Record; From b426b1738ac5a51ff82d0ff42a2cbbcf12cf6dda Mon Sep 17 00:00:00 2001 From: adammharris Date: Sat, 24 Oct 2026 18:57:35 +0000 Subject: [PATCH 2/5] build: take twig from its edit-ops branch until that major version is 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. --- Cargo.lock | 21 +++++++-------------- Cargo.toml | 16 ++++++++++------ apps/leaf-dioxus/Cargo.lock | 21 +++++++-------------- apps/leaf/Cargo.lock | 21 +++++++-------------- crates/leaf-dioxus/Cargo.lock | 21 +++++++-------------- crates/leaf-gpui/Cargo.lock | 21 +++++++-------------- 6 files changed, 45 insertions(+), 76 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c1e1a6aa..325c8213 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2640,8 +2640,7 @@ dependencies = [ [[package]] name = "twig-asciidoc" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbaea0529c2c7e65273c20116a4c6a0730c31e3b3fe49dc741a0d085d40e9ea" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -2650,8 +2649,7 @@ dependencies = [ [[package]] name = "twig-djot" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8619b5a7e9b37e5f25463b25d43424c5afea59b0d0478f0bc45e99744af4203" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -2660,8 +2658,7 @@ dependencies = [ [[package]] name = "twig-doc" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cd6cc20c4f31dd31e5e56dfa7d01f3dbdf5692695b1007e8c54640f9766193f" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-kit", ] @@ -2669,8 +2666,7 @@ dependencies = [ [[package]] name = "twig-html" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1beb6c0999dc04d89a5a0da40e585cb05a9a7c13ecb19c2e5a65085a147f62ca" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -2679,14 +2675,12 @@ dependencies = [ [[package]] name = "twig-kit" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc21949975c1e3c5ab858d0d104e9d4f4d6000e1dcfa9e46bb7dcc460bba24f" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" [[package]] name = "twig-markdown" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60ffcae233483874bec0f3c39f8a2480a087d71beb038049a9ee287e0e570745" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-html", @@ -2696,8 +2690,7 @@ dependencies = [ [[package]] name = "twig-xml" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8634fdd8e854401a1f21aef62ef80e3a87d1723ad59e810f6a633c66bf2c42c6" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", diff --git a/Cargo.toml b/Cargo.toml index 57132755..654aaccc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,12 +51,16 @@ readme = "README.md" # default `fig` feature: that is `twig::meta` (frontmatter read and edited # through fig, and a document's `twig:` key obeyed), which leaf never asks for, # and it would bring fig's YAML, TOML, JSON and figl parsers with it. -twig-doc = { version = "6", default-features = false } -twig-markdown = "6" -twig-djot = "6" -twig-html = "6" -twig-asciidoc = "6" -twig-xml = "6" +# +# From git until twig's major version with edit ops (diaryx-org/twig#18) is +# released: every edit is retain, insert and delete ops, which `Doc` hands its +# host. Back to a crates.io version once it is. +twig-doc = { git = "https://github.com/diaryx-org/twig", branch = "cc/youthful-hamilton-hid5lb", default-features = false } +twig-markdown = { git = "https://github.com/diaryx-org/twig", branch = "cc/youthful-hamilton-hid5lb" } +twig-djot = { git = "https://github.com/diaryx-org/twig", branch = "cc/youthful-hamilton-hid5lb" } +twig-html = { git = "https://github.com/diaryx-org/twig", branch = "cc/youthful-hamilton-hid5lb" } +twig-asciidoc = { git = "https://github.com/diaryx-org/twig", branch = "cc/youthful-hamilton-hid5lb" } +twig-xml = { git = "https://github.com/diaryx-org/twig", branch = "cc/youthful-hamilton-hid5lb" } # The CSS inside a `style` attribute: the presentation vocabulary is written # there, so another app renders it, and every edit to it keeps the declarations # leaf did not write. Shared with thorn, which edits an SVG's `style` the same way. diff --git a/apps/leaf-dioxus/Cargo.lock b/apps/leaf-dioxus/Cargo.lock index b96bb666..e4b652d5 100644 --- a/apps/leaf-dioxus/Cargo.lock +++ b/apps/leaf-dioxus/Cargo.lock @@ -5423,8 +5423,7 @@ dependencies = [ [[package]] name = "twig-asciidoc" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbaea0529c2c7e65273c20116a4c6a0730c31e3b3fe49dc741a0d085d40e9ea" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -5433,8 +5432,7 @@ dependencies = [ [[package]] name = "twig-djot" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8619b5a7e9b37e5f25463b25d43424c5afea59b0d0478f0bc45e99744af4203" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -5443,8 +5441,7 @@ dependencies = [ [[package]] name = "twig-doc" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cd6cc20c4f31dd31e5e56dfa7d01f3dbdf5692695b1007e8c54640f9766193f" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-kit", ] @@ -5452,8 +5449,7 @@ dependencies = [ [[package]] name = "twig-html" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1beb6c0999dc04d89a5a0da40e585cb05a9a7c13ecb19c2e5a65085a147f62ca" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -5462,14 +5458,12 @@ dependencies = [ [[package]] name = "twig-kit" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc21949975c1e3c5ab858d0d104e9d4f4d6000e1dcfa9e46bb7dcc460bba24f" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" [[package]] name = "twig-markdown" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60ffcae233483874bec0f3c39f8a2480a087d71beb038049a9ee287e0e570745" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-html", @@ -5479,8 +5473,7 @@ dependencies = [ [[package]] name = "twig-xml" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8634fdd8e854401a1f21aef62ef80e3a87d1723ad59e810f6a633c66bf2c42c6" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", diff --git a/apps/leaf/Cargo.lock b/apps/leaf/Cargo.lock index b717a0ba..74a062f8 100644 --- a/apps/leaf/Cargo.lock +++ b/apps/leaf/Cargo.lock @@ -5966,8 +5966,7 @@ dependencies = [ [[package]] name = "twig-asciidoc" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbaea0529c2c7e65273c20116a4c6a0730c31e3b3fe49dc741a0d085d40e9ea" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -5976,8 +5975,7 @@ dependencies = [ [[package]] name = "twig-djot" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8619b5a7e9b37e5f25463b25d43424c5afea59b0d0478f0bc45e99744af4203" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -5986,8 +5984,7 @@ dependencies = [ [[package]] name = "twig-doc" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cd6cc20c4f31dd31e5e56dfa7d01f3dbdf5692695b1007e8c54640f9766193f" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-kit", ] @@ -5995,8 +5992,7 @@ dependencies = [ [[package]] name = "twig-html" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1beb6c0999dc04d89a5a0da40e585cb05a9a7c13ecb19c2e5a65085a147f62ca" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -6005,14 +6001,12 @@ dependencies = [ [[package]] name = "twig-kit" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc21949975c1e3c5ab858d0d104e9d4f4d6000e1dcfa9e46bb7dcc460bba24f" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" [[package]] name = "twig-markdown" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60ffcae233483874bec0f3c39f8a2480a087d71beb038049a9ee287e0e570745" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-html", @@ -6022,8 +6016,7 @@ dependencies = [ [[package]] name = "twig-xml" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8634fdd8e854401a1f21aef62ef80e3a87d1723ad59e810f6a633c66bf2c42c6" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", diff --git a/crates/leaf-dioxus/Cargo.lock b/crates/leaf-dioxus/Cargo.lock index d8ca590c..ad7caad8 100644 --- a/crates/leaf-dioxus/Cargo.lock +++ b/crates/leaf-dioxus/Cargo.lock @@ -4804,8 +4804,7 @@ dependencies = [ [[package]] name = "twig-asciidoc" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbaea0529c2c7e65273c20116a4c6a0730c31e3b3fe49dc741a0d085d40e9ea" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -4814,8 +4813,7 @@ dependencies = [ [[package]] name = "twig-djot" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8619b5a7e9b37e5f25463b25d43424c5afea59b0d0478f0bc45e99744af4203" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -4824,8 +4822,7 @@ dependencies = [ [[package]] name = "twig-doc" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cd6cc20c4f31dd31e5e56dfa7d01f3dbdf5692695b1007e8c54640f9766193f" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-kit", ] @@ -4833,8 +4830,7 @@ dependencies = [ [[package]] name = "twig-html" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1beb6c0999dc04d89a5a0da40e585cb05a9a7c13ecb19c2e5a65085a147f62ca" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -4843,14 +4839,12 @@ dependencies = [ [[package]] name = "twig-kit" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc21949975c1e3c5ab858d0d104e9d4f4d6000e1dcfa9e46bb7dcc460bba24f" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" [[package]] name = "twig-markdown" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60ffcae233483874bec0f3c39f8a2480a087d71beb038049a9ee287e0e570745" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-html", @@ -4860,8 +4854,7 @@ dependencies = [ [[package]] name = "twig-xml" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8634fdd8e854401a1f21aef62ef80e3a87d1723ad59e810f6a633c66bf2c42c6" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", diff --git a/crates/leaf-gpui/Cargo.lock b/crates/leaf-gpui/Cargo.lock index c25e151d..21d8ff89 100644 --- a/crates/leaf-gpui/Cargo.lock +++ b/crates/leaf-gpui/Cargo.lock @@ -6025,8 +6025,7 @@ dependencies = [ [[package]] name = "twig-asciidoc" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbaea0529c2c7e65273c20116a4c6a0730c31e3b3fe49dc741a0d085d40e9ea" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -6035,8 +6034,7 @@ dependencies = [ [[package]] name = "twig-djot" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8619b5a7e9b37e5f25463b25d43424c5afea59b0d0478f0bc45e99744af4203" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -6045,8 +6043,7 @@ dependencies = [ [[package]] name = "twig-doc" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cd6cc20c4f31dd31e5e56dfa7d01f3dbdf5692695b1007e8c54640f9766193f" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-kit", ] @@ -6054,8 +6051,7 @@ dependencies = [ [[package]] name = "twig-html" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1beb6c0999dc04d89a5a0da40e585cb05a9a7c13ecb19c2e5a65085a147f62ca" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", @@ -6064,14 +6060,12 @@ dependencies = [ [[package]] name = "twig-kit" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc21949975c1e3c5ab858d0d104e9d4f4d6000e1dcfa9e46bb7dcc460bba24f" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" [[package]] name = "twig-markdown" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60ffcae233483874bec0f3c39f8a2480a087d71beb038049a9ee287e0e570745" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-html", @@ -6081,8 +6075,7 @@ dependencies = [ [[package]] name = "twig-xml" version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8634fdd8e854401a1f21aef62ef80e3a87d1723ad59e810f6a633c66bf2c42c6" +source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" dependencies = [ "twig-doc", "twig-kit", From bb217afbe06be34c0020dfdc2f3422e3250d3cfe Mon Sep 17 00:00:00 2001 From: adammharris Date: Sat, 24 Oct 2026 18:57:36 +0000 Subject: [PATCH 3/5] feat(core): every change to the text as twig's edit ops, for a host to 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. --- crates/leaf-core/src/doc/editing.rs | 35 ++--- crates/leaf-core/src/doc/file.rs | 21 +-- crates/leaf-core/src/doc/mod.rs | 10 +- crates/leaf-core/src/doc/ops.rs | 145 +++++++++++++++++++++ crates/leaf-core/src/doc/state.rs | 3 + crates/leaf-core/src/doc/tests/mod.rs | 1 + crates/leaf-core/src/doc/tests/ops.rs | 156 +++++++++++++++++++++++ crates/leaf-core/src/doc/tests/typing.rs | 11 -- crates/leaf-core/src/doc/text.rs | 24 ---- 9 files changed, 338 insertions(+), 68 deletions(-) create mode 100644 crates/leaf-core/src/doc/ops.rs create mode 100644 crates/leaf-core/src/doc/tests/ops.rs diff --git a/crates/leaf-core/src/doc/editing.rs b/crates/leaf-core/src/doc/editing.rs index 098b9aef..40a999bb 100644 --- a/crates/leaf-core/src/doc/editing.rs +++ b/crates/leaf-core/src/doc/editing.rs @@ -86,15 +86,16 @@ impl Doc { /// was — what a host does when the file changed under an open editor, as /// another device's edit arriving does. /// - /// Only the span that differs is replaced: the longest prefix and suffix - /// the two share are kept, so a caret or selection outside the change - /// stays on the characters it was on, and one inside it goes to the end - /// of what replaced it, as [`substitute`](Self::substitute) moves them. - /// Unlike a substitution, `text` is source and written exactly — nothing - /// in it is escaped — since it is the document as it now stands, not - /// something typed. An undo step of its own. `true` with nothing done - /// when the source is already `text`; `false` when the document is - /// read-only or the edit was refused. + /// Only what differs is replaced: twig's diff of the two texts + /// ([`twig::Op::diff`]), applied as one edit. A caret or selection + /// outside every change stays on the characters it was on, even between + /// two changes far apart, and one inside a change goes to the end of what + /// replaced it, as [`substitute`](Self::substitute) moves them. Unlike a + /// substitution, `text` is source and written exactly — nothing in it is + /// escaped — since it is the document as it now stands, not something + /// typed. An undo step of its own. `true` with nothing done when the + /// source is already `text`; `false` when the document is read-only or + /// the edit was refused. pub fn replace_source(&mut self, text: &str) -> bool { if self.source == text { return true; @@ -102,20 +103,8 @@ impl Doc { if self.read_only { return false; } - let (start, end, with) = differing_span(&self.source, text); - let with = with.to_owned(); - let before = self.source.len(); - let (caret, anchor) = (self.caret, self.anchor); - let pending = (self.pending_marks, self.pending_at); - self.last_edit_kind = None; - if !self.splice_exact(start, end, &with, EditKind::Other) { - self.caret = caret; - self.anchor = anchor; - self.record_caret(); - return false; - } - self.carry_selection(caret, anchor, pending, start, end, before); - true + let ops = Op::diff(&self.source, text); + self.apply_ops(&ops) } /// Put the caret and selection back after an edit of `[start, end)` that diff --git a/crates/leaf-core/src/doc/file.rs b/crates/leaf-core/src/doc/file.rs index fb1f13e1..35b11925 100644 --- a/crates/leaf-core/src/doc/file.rs +++ b/crates/leaf-core/src/doc/file.rs @@ -190,11 +190,9 @@ impl Doc { // The pre-reload caret, so undoing the swap puts it back where the // reader was standing — the same bracketing `splice_exact` does. self.record_caret(); - if self - .editor - .edit_range(0, self.source.len(), &source) - .is_ok() - { + // Only what differs, so the ops a host takes are the change and not + // the whole file, and the undo step holds no more. + if self.editor.apply(&Op::diff(&self.source, &source)).is_ok() { self.refresh(); } else { // twig wouldn't take the splice. Start over from the bytes, which is @@ -211,7 +209,10 @@ impl Doc { if let Some(g) = &mut self.undo_group { g.has_step = false; } - self.source = source.clone(); + let before = std::mem::replace(&mut self.source, source.clone()); + // A new editor, whose revisions start again: the change + // is the diff of the two texts. + self.record_ops(&before); // Not going through `refresh`, so the revision has to move // here or every frontend keeps painting the old file from // cache. @@ -240,9 +241,11 @@ impl Doc { /// funnel every edit, undo, and redo comes through — so it's where the /// revision moves, and anything cached against the text dies here. pub(super) fn refresh(&mut self) { - if let Ok(s) = self.editor.source_str() { - self.source = s; - } + let before = match self.editor.source_str() { + Ok(s) => std::mem::replace(&mut self.source, s), + Err(_) => self.source.clone(), + }; + self.record_ops(&before); self.revision += 1; // An edit is a step onto the history and the end of anything undone; // `undo`/`redo` come through here too and correct this after. diff --git a/crates/leaf-core/src/doc/mod.rs b/crates/leaf-core/src/doc/mod.rs index 1bf2241b..edf9f37d 100644 --- a/crates/leaf-core/src/doc/mod.rs +++ b/crates/leaf-core/src/doc/mod.rs @@ -34,7 +34,7 @@ use anyhow::Context; use anyhow::{Result, anyhow}; use twig::{ Alignment, BlockContainerKind, BlockKind, Change, Editor, FlatNode, Gesture, InlineKind, Kind, - NodeId, QueryMatch, + NodeId, Op, QueryMatch, }; use unicode_segmentation::GraphemeCursor; @@ -56,6 +56,7 @@ mod insert; mod marks; mod move_block; mod newline; +mod ops; mod presentation; mod splice; mod state; @@ -735,6 +736,13 @@ pub struct Doc { /// it ever drift anyway, the first undo twig refuses sets it to zero. undo_steps: usize, redo_steps: usize, + /// Every change to the text since a host last took them, as ops against + /// [`ops_base`](Self::ops_base) — see [`take_ops`](Self::take_ops). + ops: Vec, + /// The text as a host last took the ops, which `ops` read. + ops_base: String, + /// twig's revision as of the last change folded into `ops`. + ops_revision: u64, /// The undo group a host has open, if any — see /// [`begin_undo_group`](Self::begin_undo_group). `None` outside one. undo_group: Option, diff --git a/crates/leaf-core/src/doc/ops.rs b/crates/leaf-core/src/doc/ops.rs new file mode 100644 index 00000000..e9eecdfb --- /dev/null +++ b/crates/leaf-core/src/doc/ops.rs @@ -0,0 +1,145 @@ +//! The edits a host sends on: every change to the text as twig's retain, +//! insert and delete ops, gathered until the host takes them. +//! +//! twig reports each edit as the ops it made — the fewest for a gesture, so +//! bold over a word is two inserts and the word kept, and the span asked for +//! a keystroke. [`refresh`](Doc::refresh), the funnel every change comes +//! through, folds them in order into one list against the text the host last +//! took. A host sends that list where it sent the whole body, and a replica +//! that holds the same text applies it with [`twig::Op::apply`]. + +use super::*; + +impl Doc { + /// Every change to the text since the last call, or since the document + /// was opened, as one list of ops against the text then: typing, a + /// gesture, an undo, a [`replace_source`](Self::replace_source), a + /// reload. Empty when nothing changed. What a host sends on instead of + /// the whole body; [`twig::Op::apply`] of them to the text it last had + /// gives [`source`](Self::source). + pub fn take_ops(&mut self) -> Vec { + self.ops_base.clone_from(&self.source); + std::mem::take(&mut self.ops) + } + + /// Whether the text changed since the ops were last taken. + pub fn has_ops(&self) -> bool { + !self.ops.is_empty() + } + + /// Fold the change [`refresh`](Self::refresh) just read into the ops not + /// yet taken. `before` is the text before it. + /// + /// twig's ops for its last edit are the change when exactly one edit + /// landed since the last fold. Where more did (a gesture that edited and + /// rolled back before refreshing) or the editor is a new one (a reload + /// twig refused to splice), the change is the diff of the two texts. + pub(super) fn record_ops(&mut self, before: &str) { + let revision = self.editor.revision(); + let exact = revision == self.ops_revision + 1; + self.ops_revision = revision; + let edit = match exact.then(|| self.editor.last_ops().ok()).flatten() { + Some(ops) => ops, + None => Op::diff(before, &self.source), + }; + if edit.is_empty() { + return; + } + self.ops = match Op::compose(&self.ops, &edit) { + Ok(ops) => ops, + // Only ops that split a character twig inserted, which twig's own + // never do; the text the host last took is still a sound start. + Err(_) => Op::diff(&self.ops_base, &self.source), + }; + } + + /// Bring the source to `text` by `ops`, with the caret and selection + /// carried through every place they change — see + /// [`replace_source`](Self::replace_source). One undo step, bracketed by + /// the caret before and after as [`splice_exact`](Self::splice_exact) + /// brackets one. + pub(super) fn apply_ops(&mut self, ops: &[Op]) -> bool { + if self.read_only { + return false; + } + let (caret, anchor) = (self.caret, self.anchor); + let (pending_marks, pending_at) = (self.pending_marks, self.pending_at); + self.last_edit_kind = None; + self.record_caret(); + if let Err(e) = self.editor.apply(ops) { + self.status = Some(format!("edit: {e}")); + return false; + } + self.refresh(); + self.dirty = self.source != self.clean_source; + self.status = None; + let splices = splices(ops); + self.caret = carry(caret, &splices); + self.anchor = anchor + .map(|a| carry(a, &splices)) + .filter(|&a| a != self.caret); + if pending_at == Some(caret) { + self.pending_marks = pending_marks; + self.pending_at = Some(self.caret); + } else { + self.clear_pending(); + } + self.goal_col = None; + self.clamp_caret(); + // The caret the step leaves, so a redo puts it back here too. + self.record_caret(); + true + } +} + +/// The places `ops` change, in order, as `(start, end, inserted)`: the bytes +/// `[start, end)` of the text they read gave way to `inserted` bytes. +pub(super) fn splices(ops: &[Op]) -> Vec<(usize, usize, usize)> { + let mut out: Vec<(usize, usize, usize)> = Vec::new(); + let mut at = 0; + let mut open = false; + for op in ops { + match op { + Op::Retain(n) => { + at += n; + open = false; + continue; + } + Op::Insert(t) if t.is_empty() => continue, + Op::Delete(0) => continue, + _ => {} + } + if !open { + out.push((at, at, 0)); + open = true; + } + let last = out.last_mut().expect("opened above"); + match op { + Op::Insert(t) => last.2 += t.len(), + Op::Delete(n) => { + at += n; + last.1 = at; + } + Op::Retain(_) => unreachable!(), + } + } + out +} + +/// Where offset `p` of the text before `splices` lands after them: past each +/// one that ends at or before it, moved by it; inside one, at the end of what +/// replaced it; otherwise where it was. One splice moves a place exactly as +/// [`Doc::substitute`] moves the caret. +pub(super) fn carry(p: usize, splices: &[(usize, usize, usize)]) -> usize { + let mut delta: isize = 0; + for &(start, end, inserted) in splices { + if p >= end { + delta += inserted as isize - (end - start) as isize; + } else if p > start { + return (start as isize + delta) as usize + inserted; + } else { + break; + } + } + (p as isize + delta).max(0) as usize +} diff --git a/crates/leaf-core/src/doc/state.rs b/crates/leaf-core/src/doc/state.rs index e7a7e230..15bc9252 100644 --- a/crates/leaf-core/src/doc/state.rs +++ b/crates/leaf-core/src/doc/state.rs @@ -143,6 +143,7 @@ impl Doc { path, disk_hash, clean_source: source.clone(), + ops_base: source.clone(), source, caret: 0, anchor: None, @@ -173,6 +174,8 @@ impl Doc { revision: 0, undo_steps: 0, redo_steps: 0, + ops: Vec::new(), + ops_revision: 0, undo_group: None, #[cfg(test)] refuse_next_literal: false, diff --git a/crates/leaf-core/src/doc/tests/mod.rs b/crates/leaf-core/src/doc/tests/mod.rs index f9d396d5..b0dccc84 100644 --- a/crates/leaf-core/src/doc/tests/mod.rs +++ b/crates/leaf-core/src/doc/tests/mod.rs @@ -18,6 +18,7 @@ mod mark_edges; mod math; mod motion; mod move_block; +mod ops; mod presentation; mod ragged_formats; mod rich_view; diff --git a/crates/leaf-core/src/doc/tests/ops.rs b/crates/leaf-core/src/doc/tests/ops.rs new file mode 100644 index 00000000..059de469 --- /dev/null +++ b/crates/leaf-core/src/doc/tests/ops.rs @@ -0,0 +1,156 @@ +//! The ops a host takes: every change to the text as twig's retain, insert +//! and delete ops, and `replace_source` and a reload made of them. + +use super::*; + +/// Take the ops and check they bring `base` to the source. +fn take_onto(d: &mut Doc, base: &str) -> Vec { + let ops = d.take_ops(); + assert_eq!( + Op::apply(base, &ops).unwrap(), + d.source, + "ops {ops:?} onto {base:?}" + ); + ops +} + +#[test] +fn typing_is_one_list_of_ops_against_the_text_last_taken() { + let mut d = doc_with("ops-typing", "hello\n"); + assert!(!d.has_ops()); + assert_eq!(d.take_ops(), vec![]); + d.caret = 5; + for c in [" ", "w", "o", "r", "l", "d"] { + d.insert(c); + } + assert!(d.has_ops()); + let ops = take_onto(&mut d, "hello\n"); + assert_eq!(ops, vec![Op::Retain(5), Op::Insert(" world".into())]); + assert!(!d.has_ops()); + + d.backspace(); + let ops = take_onto(&mut d, "hello world\n"); + assert_eq!(ops, vec![Op::Retain(10), Op::Delete(1)]); +} + +#[test] +fn a_gesture_is_the_fewest_ops_that_make_it() { + let mut d = doc_with("ops-bold", "a word here\n"); + d.select_range(2, 6); + d.toggle(InlineKind::Strong); + assert_eq!(d.source, "a **word** here\n"); + // The word is kept, not deleted and written again — what lets a merge + // keep an edit someone else made inside it. + assert_eq!( + take_onto(&mut d, "a word here\n"), + vec![ + Op::Retain(2), + Op::Insert("**".into()), + Op::Retain(4), + Op::Insert("**".into()) + ] + ); +} + +#[test] +fn an_undo_and_a_redo_are_changes_like_any_other() { + let mut d = doc_with("ops-undo", "one\n"); + d.caret = 3; + d.insert("!"); + let base = d.source.clone(); + d.take_ops(); + assert!(d.undo()); + assert_eq!(take_onto(&mut d, &base), vec![Op::Retain(3), Op::Delete(1)]); + assert!(d.redo()); + assert_eq!( + take_onto(&mut d, "one\n"), + vec![Op::Retain(3), Op::Insert("!".into())] + ); +} + +#[test] +fn edits_that_cancel_out_leave_no_ops() { + let mut d = doc_with("ops-cancel", "abc\n"); + d.caret = 3; + d.insert("x"); + d.backspace(); + assert_eq!(d.source, "abc\n"); + assert!(!d.has_ops()); +} + +#[test] +fn every_kind_of_change_composes_onto_the_text_last_taken() { + let mut d = doc_with("ops-mixed", "# Title\n\nsome text here\n\n- one\n- two\n"); + let base = d.source.clone(); + d.caret = d.source.find("text").unwrap(); + d.insert("more "); + d.select_range(0, 7); + d.toggle(InlineKind::Emph); + d.caret = d.source.len(); + d.insert("- three"); + d.newline(); + d.undo(); + d.redo(); + assert!(d.replace_source(&d.source.replace("some", "any"))); + take_onto(&mut d, &base); +} + +#[test] +fn replace_source_keeps_a_caret_between_two_changes_on_its_text() { + let mut d = doc_with("ops-replace", "one\n\ntwo\n\nthree\n"); + d.caret = d.source.find("two").unwrap() + 1; + d.select_range(d.caret, d.caret + 1); + let (caret, anchor) = (d.caret, d.anchor); + assert!(d.replace_source("1st:\n\ntwo\n\nthree!\n")); + // Both changes are around the selection: one before it moves it along, + // one after it does not. One span from the first to the last would have + // swallowed it and sent the caret to the end of the file. + assert_eq!(d.caret, caret + 1); + assert_eq!(d.anchor, anchor.map(|a| a + 1)); + assert_eq!(&d.source[d.caret - 1..d.caret], "w"); + assert_eq!( + take_onto(&mut d, "one\n\ntwo\n\nthree\n"), + vec![ + Op::Insert("1st:".into()), + Op::Delete(3), + Op::Retain(12), + Op::Insert("!".into()) + ] + ); + // One undo step. + assert!(d.undo()); + assert_eq!(d.source, "one\n\ntwo\n\nthree\n"); +} + +#[test] +fn a_reload_is_the_ops_of_what_changed_and_not_the_whole_file() { + let mut d = doc_with("ops-reload", "alpha\n\nbeta\n"); + std::fs::write(&d.path, "alpha\n\nbeta, again\n").unwrap(); + d.reload(); + assert_eq!(d.source, "alpha\n\nbeta, again\n"); + assert!(!d.dirty); + assert_eq!( + take_onto(&mut d, "alpha\n\nbeta\n"), + vec![Op::Retain(11), Op::Insert(", again".into())] + ); +} + +#[test] +fn carry_moves_a_place_past_changes_before_it_only() { + use crate::doc::ops::{carry, splices}; + let ops = [ + Op::Retain(2), + Op::Insert("xx".into()), + Op::Delete(1), + Op::Retain(3), + Op::Insert("y".into()), + ]; + let s = splices(&ops); + assert_eq!(s, vec![(2, 3, 2), (6, 6, 1)]); + assert_eq!(carry(1, &s), 1); // before both + assert_eq!(carry(2, &s), 2); // at the first's start: stays + assert_eq!(carry(3, &s), 4); // at its end: moves with it + assert_eq!(carry(5, &s), 6); // between the two + assert_eq!(carry(6, &s), 8); // at an insert: after it, as a splice moves it + assert_eq!(carry(9, &s), 11); // past both +} diff --git a/crates/leaf-core/src/doc/tests/typing.rs b/crates/leaf-core/src/doc/tests/typing.rs index c2be6dd9..1f3de579 100644 --- a/crates/leaf-core/src/doc/tests/typing.rs +++ b/crates/leaf-core/src/doc/tests/typing.rs @@ -167,17 +167,6 @@ fn replacing_the_source_writes_markup_as_markup() { assert!(d.replace_source("**bold** and *it*\n"), "already there"); } -#[test] -fn the_differing_span_ends_on_characters() { - assert_eq!(differing_span("abc", "abc"), (3, 3, "")); - assert_eq!(differing_span("abXc", "abYc"), (2, 3, "Y")); - assert_eq!(differing_span("aaa", "aaaa"), (3, 3, "a")); - assert_eq!(differing_span("aaaa", "aa"), (2, 4, "")); - // é and è share their first byte; the span must not split it. - assert_eq!(differing_span("café", "cafè"), (3, 5, "è")); - assert_eq!(differing_span("", "x"), (0, 0, "x")); -} - #[test] fn a_substitution_behind_the_caret_leaves_the_caret_and_is_its_own_step() { let mut d = wysiwyg_doc("substitute", "\n"); diff --git a/crates/leaf-core/src/doc/text.rs b/crates/leaf-core/src/doc/text.rs index 11a63429..b80b2347 100644 --- a/crates/leaf-core/src/doc/text.rs +++ b/crates/leaf-core/src/doc/text.rs @@ -571,27 +571,3 @@ pub(super) fn detect_format(path: &Path) -> Result { other => return Err(anyhow!("unknown document extension: .{other}")), }) } - -/// The one span `from` and `to` differ in: `[start, end)` of `from`, and -/// what `to` holds there. The longest shared prefix, then the longest shared -/// suffix of what is left — never overlapping it — each ended on a character -/// boundary of both. -pub(super) fn differing_span<'a>(from: &str, to: &'a str) -> (usize, usize, &'a str) { - let (a, b) = (from.as_bytes(), to.as_bytes()); - let mut prefix = a.iter().zip(b).take_while(|(x, y)| x == y).count(); - while !(from.is_char_boundary(prefix) && to.is_char_boundary(prefix)) { - prefix -= 1; - } - let most = a.len().min(b.len()) - prefix; - let mut suffix = a - .iter() - .rev() - .zip(b.iter().rev()) - .take(most) - .take_while(|(x, y)| x == y) - .count(); - while !(from.is_char_boundary(a.len() - suffix) && to.is_char_boundary(b.len() - suffix)) { - suffix -= 1; - } - (prefix, a.len() - suffix, &to[prefix..b.len() - suffix]) -} From eca0164640b8aef8f5abf567def165143064d54d Mon Sep 17 00:00:00 2001 From: Adam Harris Date: Mon, 26 Oct 2026 13:30:45 -0600 Subject: [PATCH 4/5] build: take twig 7 from crates.io, now that edit ops are released 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. --- Cargo.lock | 35 ++++++++++++++++++++------------- Cargo.toml | 16 ++++++--------- apps/leaf-dioxus-tui/Cargo.lock | 31 +++++++++++++++-------------- apps/leaf-dioxus/Cargo.lock | 35 ++++++++++++++++++++------------- apps/leaf/Cargo.lock | 35 ++++++++++++++++++++------------- crates/leaf-core/src/doc/ops.rs | 2 +- crates/leaf-dioxus/Cargo.lock | 35 ++++++++++++++++++++------------- crates/leaf-gpui/Cargo.lock | 35 ++++++++++++++++++++------------- 8 files changed, 128 insertions(+), 96 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 325c8213..7c29c3a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2639,8 +2639,9 @@ dependencies = [ [[package]] name = "twig-asciidoc" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3583fcbd776b3c7e009c95be1a09e8b8cd5986db0369f02433839155567fb35b" dependencies = [ "twig-doc", "twig-kit", @@ -2648,8 +2649,9 @@ dependencies = [ [[package]] name = "twig-djot" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9df7623ba396e17d9890d2432249002f76780b1b44b6a8f8791cd2e8806ec899" dependencies = [ "twig-doc", "twig-kit", @@ -2657,16 +2659,18 @@ dependencies = [ [[package]] name = "twig-doc" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43059a77c9c1b7e56f38a74917a4e446da813388ab9a6227520081abf4fb5ebc" dependencies = [ "twig-kit", ] [[package]] name = "twig-html" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d0f5733e9d1cf54d306105e89d9a4388a36e1a77110065214dacc681adfcacc" dependencies = [ "twig-doc", "twig-kit", @@ -2674,13 +2678,15 @@ dependencies = [ [[package]] name = "twig-kit" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "547e69372eacfac62d3bc3c0433683894d9b0743aa413311c50a0732ae890397" [[package]] name = "twig-markdown" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e82b47b5b941022c8ce086f8c32c36e563482c1a2a74805abd2398eadbacd1" dependencies = [ "twig-doc", "twig-html", @@ -2689,8 +2695,9 @@ dependencies = [ [[package]] name = "twig-xml" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47e9676fbc4dd21759bc478aaea2111dd85c55e102048e7a67f7bde6d55621" dependencies = [ "twig-doc", "twig-kit", diff --git a/Cargo.toml b/Cargo.toml index 654aaccc..7d5402ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,16 +51,12 @@ readme = "README.md" # default `fig` feature: that is `twig::meta` (frontmatter read and edited # through fig, and a document's `twig:` key obeyed), which leaf never asks for, # and it would bring fig's YAML, TOML, JSON and figl parsers with it. -# -# From git until twig's major version with edit ops (diaryx-org/twig#18) is -# released: every edit is retain, insert and delete ops, which `Doc` hands its -# host. Back to a crates.io version once it is. -twig-doc = { git = "https://github.com/diaryx-org/twig", branch = "cc/youthful-hamilton-hid5lb", default-features = false } -twig-markdown = { git = "https://github.com/diaryx-org/twig", branch = "cc/youthful-hamilton-hid5lb" } -twig-djot = { git = "https://github.com/diaryx-org/twig", branch = "cc/youthful-hamilton-hid5lb" } -twig-html = { git = "https://github.com/diaryx-org/twig", branch = "cc/youthful-hamilton-hid5lb" } -twig-asciidoc = { git = "https://github.com/diaryx-org/twig", branch = "cc/youthful-hamilton-hid5lb" } -twig-xml = { git = "https://github.com/diaryx-org/twig", branch = "cc/youthful-hamilton-hid5lb" } +twig-doc = { version = "7", default-features = false } +twig-markdown = "7" +twig-djot = "7" +twig-html = "7" +twig-asciidoc = "7" +twig-xml = "7" # The CSS inside a `style` attribute: the presentation vocabulary is written # there, so another app renders it, and every edit to it keeps the declarations # leaf did not write. Shared with thorn, which edits an SVG's `style` the same way. diff --git a/apps/leaf-dioxus-tui/Cargo.lock b/apps/leaf-dioxus-tui/Cargo.lock index 203d8c47..f96749d0 100644 --- a/apps/leaf-dioxus-tui/Cargo.lock +++ b/apps/leaf-dioxus-tui/Cargo.lock @@ -2564,6 +2564,7 @@ dependencies = [ name = "leaf-dioxus" version = "0.0.0" dependencies = [ + "accesskit", "arboard", "dioxus", "dioxus-native", @@ -4887,7 +4888,7 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c2499c2d826531388872b2268718aed907a39bd785ab0dcfe57fab26283f92e" dependencies = [ - "skrifa 0.40.0", + "skrifa 0.44.0", "yazi", "zeno", ] @@ -5385,9 +5386,9 @@ dependencies = [ [[package]] name = "twig-asciidoc" -version = "6.0.0" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbaea0529c2c7e65273c20116a4c6a0730c31e3b3fe49dc741a0d085d40e9ea" +checksum = "3583fcbd776b3c7e009c95be1a09e8b8cd5986db0369f02433839155567fb35b" dependencies = [ "twig-doc", "twig-kit", @@ -5395,9 +5396,9 @@ dependencies = [ [[package]] name = "twig-djot" -version = "6.0.0" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8619b5a7e9b37e5f25463b25d43424c5afea59b0d0478f0bc45e99744af4203" +checksum = "9df7623ba396e17d9890d2432249002f76780b1b44b6a8f8791cd2e8806ec899" dependencies = [ "twig-doc", "twig-kit", @@ -5405,18 +5406,18 @@ dependencies = [ [[package]] name = "twig-doc" -version = "6.0.0" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cd6cc20c4f31dd31e5e56dfa7d01f3dbdf5692695b1007e8c54640f9766193f" +checksum = "43059a77c9c1b7e56f38a74917a4e446da813388ab9a6227520081abf4fb5ebc" dependencies = [ "twig-kit", ] [[package]] name = "twig-html" -version = "6.0.0" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1beb6c0999dc04d89a5a0da40e585cb05a9a7c13ecb19c2e5a65085a147f62ca" +checksum = "7d0f5733e9d1cf54d306105e89d9a4388a36e1a77110065214dacc681adfcacc" dependencies = [ "twig-doc", "twig-kit", @@ -5424,15 +5425,15 @@ dependencies = [ [[package]] name = "twig-kit" -version = "6.0.0" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc21949975c1e3c5ab858d0d104e9d4f4d6000e1dcfa9e46bb7dcc460bba24f" +checksum = "547e69372eacfac62d3bc3c0433683894d9b0743aa413311c50a0732ae890397" [[package]] name = "twig-markdown" -version = "6.0.0" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60ffcae233483874bec0f3c39f8a2480a087d71beb038049a9ee287e0e570745" +checksum = "a3e82b47b5b941022c8ce086f8c32c36e563482c1a2a74805abd2398eadbacd1" dependencies = [ "twig-doc", "twig-html", @@ -5441,9 +5442,9 @@ dependencies = [ [[package]] name = "twig-xml" -version = "6.0.0" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8634fdd8e854401a1f21aef62ef80e3a87d1723ad59e810f6a633c66bf2c42c6" +checksum = "eb47e9676fbc4dd21759bc478aaea2111dd85c55e102048e7a67f7bde6d55621" dependencies = [ "twig-doc", "twig-kit", diff --git a/apps/leaf-dioxus/Cargo.lock b/apps/leaf-dioxus/Cargo.lock index e4b652d5..5bec17ae 100644 --- a/apps/leaf-dioxus/Cargo.lock +++ b/apps/leaf-dioxus/Cargo.lock @@ -5422,8 +5422,9 @@ dependencies = [ [[package]] name = "twig-asciidoc" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3583fcbd776b3c7e009c95be1a09e8b8cd5986db0369f02433839155567fb35b" dependencies = [ "twig-doc", "twig-kit", @@ -5431,8 +5432,9 @@ dependencies = [ [[package]] name = "twig-djot" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9df7623ba396e17d9890d2432249002f76780b1b44b6a8f8791cd2e8806ec899" dependencies = [ "twig-doc", "twig-kit", @@ -5440,16 +5442,18 @@ dependencies = [ [[package]] name = "twig-doc" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43059a77c9c1b7e56f38a74917a4e446da813388ab9a6227520081abf4fb5ebc" dependencies = [ "twig-kit", ] [[package]] name = "twig-html" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d0f5733e9d1cf54d306105e89d9a4388a36e1a77110065214dacc681adfcacc" dependencies = [ "twig-doc", "twig-kit", @@ -5457,13 +5461,15 @@ dependencies = [ [[package]] name = "twig-kit" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "547e69372eacfac62d3bc3c0433683894d9b0743aa413311c50a0732ae890397" [[package]] name = "twig-markdown" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e82b47b5b941022c8ce086f8c32c36e563482c1a2a74805abd2398eadbacd1" dependencies = [ "twig-doc", "twig-html", @@ -5472,8 +5478,9 @@ dependencies = [ [[package]] name = "twig-xml" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47e9676fbc4dd21759bc478aaea2111dd85c55e102048e7a67f7bde6d55621" dependencies = [ "twig-doc", "twig-kit", diff --git a/apps/leaf/Cargo.lock b/apps/leaf/Cargo.lock index 74a062f8..5281fb78 100644 --- a/apps/leaf/Cargo.lock +++ b/apps/leaf/Cargo.lock @@ -5965,8 +5965,9 @@ dependencies = [ [[package]] name = "twig-asciidoc" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3583fcbd776b3c7e009c95be1a09e8b8cd5986db0369f02433839155567fb35b" dependencies = [ "twig-doc", "twig-kit", @@ -5974,8 +5975,9 @@ dependencies = [ [[package]] name = "twig-djot" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9df7623ba396e17d9890d2432249002f76780b1b44b6a8f8791cd2e8806ec899" dependencies = [ "twig-doc", "twig-kit", @@ -5983,16 +5985,18 @@ dependencies = [ [[package]] name = "twig-doc" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43059a77c9c1b7e56f38a74917a4e446da813388ab9a6227520081abf4fb5ebc" dependencies = [ "twig-kit", ] [[package]] name = "twig-html" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d0f5733e9d1cf54d306105e89d9a4388a36e1a77110065214dacc681adfcacc" dependencies = [ "twig-doc", "twig-kit", @@ -6000,13 +6004,15 @@ dependencies = [ [[package]] name = "twig-kit" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "547e69372eacfac62d3bc3c0433683894d9b0743aa413311c50a0732ae890397" [[package]] name = "twig-markdown" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e82b47b5b941022c8ce086f8c32c36e563482c1a2a74805abd2398eadbacd1" dependencies = [ "twig-doc", "twig-html", @@ -6015,8 +6021,9 @@ dependencies = [ [[package]] name = "twig-xml" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47e9676fbc4dd21759bc478aaea2111dd85c55e102048e7a67f7bde6d55621" dependencies = [ "twig-doc", "twig-kit", diff --git a/crates/leaf-core/src/doc/ops.rs b/crates/leaf-core/src/doc/ops.rs index e9eecdfb..a56ecf12 100644 --- a/crates/leaf-core/src/doc/ops.rs +++ b/crates/leaf-core/src/doc/ops.rs @@ -45,7 +45,7 @@ impl Doc { if edit.is_empty() { return; } - self.ops = match Op::compose(&self.ops, &edit) { + self.ops = match Op::compose(&self.ops_base, &self.ops, &edit) { Ok(ops) => ops, // Only ops that split a character twig inserted, which twig's own // never do; the text the host last took is still a sound start. diff --git a/crates/leaf-dioxus/Cargo.lock b/crates/leaf-dioxus/Cargo.lock index ad7caad8..88859fa3 100644 --- a/crates/leaf-dioxus/Cargo.lock +++ b/crates/leaf-dioxus/Cargo.lock @@ -4803,8 +4803,9 @@ dependencies = [ [[package]] name = "twig-asciidoc" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3583fcbd776b3c7e009c95be1a09e8b8cd5986db0369f02433839155567fb35b" dependencies = [ "twig-doc", "twig-kit", @@ -4812,8 +4813,9 @@ dependencies = [ [[package]] name = "twig-djot" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9df7623ba396e17d9890d2432249002f76780b1b44b6a8f8791cd2e8806ec899" dependencies = [ "twig-doc", "twig-kit", @@ -4821,16 +4823,18 @@ dependencies = [ [[package]] name = "twig-doc" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43059a77c9c1b7e56f38a74917a4e446da813388ab9a6227520081abf4fb5ebc" dependencies = [ "twig-kit", ] [[package]] name = "twig-html" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d0f5733e9d1cf54d306105e89d9a4388a36e1a77110065214dacc681adfcacc" dependencies = [ "twig-doc", "twig-kit", @@ -4838,13 +4842,15 @@ dependencies = [ [[package]] name = "twig-kit" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "547e69372eacfac62d3bc3c0433683894d9b0743aa413311c50a0732ae890397" [[package]] name = "twig-markdown" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e82b47b5b941022c8ce086f8c32c36e563482c1a2a74805abd2398eadbacd1" dependencies = [ "twig-doc", "twig-html", @@ -4853,8 +4859,9 @@ dependencies = [ [[package]] name = "twig-xml" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47e9676fbc4dd21759bc478aaea2111dd85c55e102048e7a67f7bde6d55621" dependencies = [ "twig-doc", "twig-kit", diff --git a/crates/leaf-gpui/Cargo.lock b/crates/leaf-gpui/Cargo.lock index 21d8ff89..274f2db3 100644 --- a/crates/leaf-gpui/Cargo.lock +++ b/crates/leaf-gpui/Cargo.lock @@ -6024,8 +6024,9 @@ dependencies = [ [[package]] name = "twig-asciidoc" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3583fcbd776b3c7e009c95be1a09e8b8cd5986db0369f02433839155567fb35b" dependencies = [ "twig-doc", "twig-kit", @@ -6033,8 +6034,9 @@ dependencies = [ [[package]] name = "twig-djot" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9df7623ba396e17d9890d2432249002f76780b1b44b6a8f8791cd2e8806ec899" dependencies = [ "twig-doc", "twig-kit", @@ -6042,16 +6044,18 @@ dependencies = [ [[package]] name = "twig-doc" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43059a77c9c1b7e56f38a74917a4e446da813388ab9a6227520081abf4fb5ebc" dependencies = [ "twig-kit", ] [[package]] name = "twig-html" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d0f5733e9d1cf54d306105e89d9a4388a36e1a77110065214dacc681adfcacc" dependencies = [ "twig-doc", "twig-kit", @@ -6059,13 +6063,15 @@ dependencies = [ [[package]] name = "twig-kit" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "547e69372eacfac62d3bc3c0433683894d9b0743aa413311c50a0732ae890397" [[package]] name = "twig-markdown" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e82b47b5b941022c8ce086f8c32c36e563482c1a2a74805abd2398eadbacd1" dependencies = [ "twig-doc", "twig-html", @@ -6074,8 +6080,9 @@ dependencies = [ [[package]] name = "twig-xml" -version = "6.0.0" -source = "git+https://github.com/diaryx-org/twig?branch=cc%2Fyouthful-hamilton-hid5lb#8f14298a7d463647c2440f90d2a032b291227747" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47e9676fbc4dd21759bc478aaea2111dd85c55e102048e7a67f7bde6d55621" dependencies = [ "twig-doc", "twig-kit", From a5d1029a094d6908d59937e9e6a813f49e43ccb5 Mon Sep 17 00:00:00 2001 From: Adam Harris Date: Mon, 26 Oct 2026 13:30:45 -0600 Subject: [PATCH 5/5] fix(swift): regenerate the UniFFI binding, whose insert_directive checksum was stale --- .../leaf-swift/uniffi-generated/Sources/LeafFFI/leaf_ffi.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/leaf-swift/uniffi-generated/Sources/LeafFFI/leaf_ffi.swift b/packages/leaf-swift/uniffi-generated/Sources/LeafFFI/leaf_ffi.swift index 99a6a558..493ddb23 100644 --- a/packages/leaf-swift/uniffi-generated/Sources/LeafFFI/leaf_ffi.swift +++ b/packages/leaf-swift/uniffi-generated/Sources/LeafFFI/leaf_ffi.swift @@ -11030,7 +11030,7 @@ private let initializationResult: InitializationResult = { if (uniffi_leaf_ffi_checksum_method_leafdoc_insert() != 57472) { return InitializationResult.apiChecksumMismatch } - if (uniffi_leaf_ffi_checksum_method_leafdoc_insert_directive() != 45079) { + if (uniffi_leaf_ffi_checksum_method_leafdoc_insert_directive() != 3768) { return InitializationResult.apiChecksumMismatch } if (uniffi_leaf_ffi_checksum_method_leafdoc_insert_footnote() != 24840) {