diff --git a/Cargo.lock b/Cargo.lock index 5a2ba3c2..86c901db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1553,9 +1553,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", @@ -1563,9 +1563,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", @@ -1573,18 +1573,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", @@ -1592,15 +1592,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", @@ -1609,9 +1609,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/Cargo.toml b/Cargo.toml index 64e5038a..2160da2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,12 +33,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. -twig-doc = { version = "6", default-features = false } -twig-markdown = "6" -twig-djot = "6" -twig-html = "6" -twig-asciidoc = "6" -twig-xml = "6" +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 b96bb666..5bec17ae 100644 --- a/apps/leaf-dioxus/Cargo.lock +++ b/apps/leaf-dioxus/Cargo.lock @@ -5422,9 +5422,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", @@ -5432,9 +5432,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", @@ -5442,18 +5442,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", @@ -5461,15 +5461,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", @@ -5478,9 +5478,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/archive/apps/leaf/Cargo.lock b/archive/apps/leaf/Cargo.lock index b717a0ba..5281fb78 100644 --- a/archive/apps/leaf/Cargo.lock +++ b/archive/apps/leaf/Cargo.lock @@ -5965,9 +5965,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", @@ -5975,9 +5975,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", @@ -5985,18 +5985,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", @@ -6004,15 +6004,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", @@ -6021,9 +6021,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/archive/crates/leaf-ffi/src/lib.rs b/archive/crates/leaf-ffi/src/lib.rs index b79c9ba0..05f7ffa8 100644 --- a/archive/crates/leaf-ffi/src/lib.rs +++ b/archive/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/archive/crates/leaf-gpui/Cargo.lock b/archive/crates/leaf-gpui/Cargo.lock index c25e151d..274f2db3 100644 --- a/archive/crates/leaf-gpui/Cargo.lock +++ b/archive/crates/leaf-gpui/Cargo.lock @@ -6024,9 +6024,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", @@ -6034,9 +6034,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", @@ -6044,18 +6044,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", @@ -6063,15 +6063,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", @@ -6080,9 +6080,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/archive/crates/leaf-wasm/src/lib.rs b/archive/crates/leaf-wasm/src/lib.rs index fad99d7a..5bdb7049 100644 --- a/archive/crates/leaf-wasm/src/lib.rs +++ b/archive/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/archive/packages/leaf-swift/Sources/LeafUI/DirectiveItem.swift b/archive/packages/leaf-swift/Sources/LeafUI/DirectiveItem.swift index 66f62bcd..cd413dfc 100644 --- a/archive/packages/leaf-swift/Sources/LeafUI/DirectiveItem.swift +++ b/archive/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/archive/packages/leaf-swift/Sources/LeafUI/LeafEditorView.swift b/archive/packages/leaf-swift/Sources/LeafUI/LeafEditorView.swift index d27f216d..cf18e80b 100644 --- a/archive/packages/leaf-swift/Sources/LeafUI/LeafEditorView.swift +++ b/archive/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/archive/packages/leaf-swift/Tests/LeafUITests/DirectiveCatalogueTests.swift b/archive/packages/leaf-swift/Tests/LeafUITests/DirectiveCatalogueTests.swift index 3af18c4e..8d4f90bc 100644 --- a/archive/packages/leaf-swift/Tests/LeafUITests/DirectiveCatalogueTests.swift +++ b/archive/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/archive/packages/leaf-swift/uniffi-generated/Sources/LeafFFI/leaf_ffi.swift b/archive/packages/leaf-swift/uniffi-generated/Sources/LeafFFI/leaf_ffi.swift index 5f7a4e18..493ddb23 100644 --- a/archive/packages/leaf-swift/uniffi-generated/Sources/LeafFFI/leaf_ffi.swift +++ b/archive/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, @@ -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) { diff --git a/archive/packages/leaf-web/src/editor.d.ts b/archive/packages/leaf-web/src/editor.d.ts index 2295325f..7e6ddf22 100644 --- a/archive/packages/leaf-web/src/editor.d.ts +++ b/archive/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; 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..a56ecf12 --- /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_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. + 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/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/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/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-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]) -} diff --git a/crates/leaf-dioxus/Cargo.lock b/crates/leaf-dioxus/Cargo.lock index d8ca590c..88859fa3 100644 --- a/crates/leaf-dioxus/Cargo.lock +++ b/crates/leaf-dioxus/Cargo.lock @@ -4803,9 +4803,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", @@ -4813,9 +4813,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", @@ -4823,18 +4823,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", @@ -4842,15 +4842,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", @@ -4859,9 +4859,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",