diff --git a/AGENTS.md b/AGENTS.md index 5542150..4342b49 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,7 +13,7 @@ Ely GPUI Component. A component library for GPUI, in light and dark. - Web views: `wry` 0.57 (Apache-2.0 OR MIT, default features off, macOS only) lays a child WKWebView over the window. - Terminal: `alacritty_terminal` 0.26 (Apache-2.0, default features off, native only) for the grid, its parser and the pseudo-terminal; `futures` carries its events. `vte` 0.15 (Apache-2.0 OR MIT), the parser it re-exports, reads `AnsiText`'s codes alone, so colored output builds for wasm32. - Diffs: `similar` 3.2 (Apache-2.0) for line and word diffs and three-way merges; its `unicode` feature splits words at punctuation. -- Markdown: `markdown` 1.0.0 (markdown-rs, MIT) reads GitHub's flavor and math into a syntax tree with byte positions for `MarkdownRenderer`, `MarkdownEditor`, the highlights, block ranges and outline. `MarkdownRenderer` draws display math through `typography::Latex`, a ```` ```mermaid ```` block through `documents::Diagram`, and pictures from the owner's folder (`base`) or `data:` addresses (`base64` 0.22, MIT OR Apache-2.0); web pictures stay unloaded. Inline math shows as TeX: gpui text carries no inline pictures. Inline it reads as Typora's defaults: `:shortcode:` turns to its emoji as GitHub reads it (the `emojis` crate's names, GitHub's today, so `:cricket:` is the insect; read after escapes and references, so `\:smile:` turns too; inside an autolink, `` or a filtered tag it stays text), inline HTML's `u`, `b`/`strong`, `i`/`em`, `s`/`del`/`strike`, `code`/`kbd`, `mark`, `br` and `a href` draw as what they mean GFM's filtered tags (`script`, `style`, `title`, `textarea`, `iframe`, `xmp`, `noembed`, `noframes`, `plaintext`) show as text, and other tags, hyphenated names too, vanish, leaving their text; a tag's name runs to white space or `/`, as HTML5 reads it; attribute values split on ASCII whitespace alone and decode as HTML decodes them; each Markdown container is the element GitHub writes (`em`, `strong`, `del`, `a`), on one stack with the tags and repaired as HTML5 repairs: an end tag closes the innermost element of its name and all above it, of which only formatting elements (`a`, `b`, `code`, `em`, `i`, `s`, `strike`, `strong`, `u`) reopen, a new `a` ends the open one and an `a` without `href` links nothing; other tags are not tracked, and `
` breaks as `
` does; and a footnote reference is its number in superscript, numbered by first reference, as its definition is; one `~` still strikes. At the root, blocks read as GitHub shows them: a quote whose first line is plain text reading `[!NOTE]`, `[!TIP]`, `[!IMPORTANT]`, `[!WARNING]` or `[!CAUTION]` in any case, after escapes and references, spaces and tabs around it, with more after it, is an alert under its title (Important in the palette's violet, `syntax.keyword`, read at 4.5:1); a paragraph that is `[toc]` alone, as Typora reads it, lists every heading by depth, and a press on one reveals it as a link press does (`MarkdownDocument`'s `reveal`), the heading moved by the one edit between the text the list drew from and the text now, gone if that edit took it, and a secondary press acts on press, since a block writing back moves the list; front matter shows in a box without its fences; an HTML block shows its text with the inline tags above, white space collapsed and owed as a browser lays it, block elements breaking lines and closing what opened inside them, a block's start ending an open `p` and an `li` start an `li`, a `dd` or `dt` start either, as HTML5 ends them, comments dropped, the filtered tags shown as text, and an unclosed tag dropping the rest; a rule is a 2px `border_strong` line; bullets go •, ◦, ▪ by list depth, ordered lists counted. `MarkdownDocument` holds a whole file in one `CodeEditor` (text and undo, colored by `CodeEditor::highlighter` with `markdown_highlights`): visual draws the file's top-level blocks in a gpui `list`, a pressed block opening as its source in a `TextInput` whose typing is the document's text at once and whose write-back is one undo step; source is the editor; preview draws without presses. A written-back block, a mode switch or a new text is read at once up to 128 KiB, longer ones on the background executor; typing in source or split reads 300 ms after the last key, off the main thread (markdown-rs grows with the square of a paragraph's lines: 40,000 lines take 0.9 s). Texts past `LARGEST_READ` (2 MiB) are never read: no blocks, no outline. A new read keeps the list's blocks alike at both ends. One caret serves every mode: the editor's selection, which a written-back block moves; `set_caret` and `set_top_line` set caret and view apart; a top line asked (numbered, so a late frame callback finishes only its own ask; new text places it again, clamped to the text as it then is) waits for the read, lands on its block, then a frame later at its share of the block's height; `reveal` is such an ask with the caret at its line; a switch between source and the list keeps the top line, one between visual and preview keeps the list's scroll as it is. A block opens only when the read is of the text as it is now. A pressed block keeps its identity across the write-back of the one before it. Blocks are Tab stops that Enter or Space opens; preview takes no presses, undo or redo. `CodeEditor` keeps at most 64 MiB of undo and redo text, dropping the oldest undo and then the farthest redo after every record, composition, undo and redo. `BlockData::from_markdown` and its export still read with `pulldown-cmark` 0.13 (MIT, default features off); it adds GitHub's alerts, a callout's form, and reads each field's inline Markdown from the source by offset, as written. +- Markdown: `markdown` 1.0.0 (markdown-rs, MIT) reads GitHub's flavor and math into a syntax tree with byte positions for `MarkdownRenderer`, `MarkdownEditor`, the highlights, block ranges and outline. `MarkdownRenderer` draws display math through `typography::Latex`, a ```` ```mermaid ```` block through `documents::Diagram`, and pictures from the owner's folder (`base`) or `data:` addresses (`base64` 0.22, MIT OR Apache-2.0); web pictures stay unloaded. Inline math shows as TeX: gpui text carries no inline pictures. Inline it reads as Typora's defaults: `:shortcode:` turns to its emoji as GitHub reads it (the `emojis` crate's names, GitHub's today, so `:cricket:` is the insect; read after escapes and references, so `\:smile:` turns too; inside an autolink or `` it stays text; within one DOM text node, which filtered tags do not split, the first `:name:`-shaped run decides for all: blank text or a space before it turns every shortcode, else none, so `x:smile: :smile:` stays), inline HTML's `u`, `b`/`strong`, `i`/`em`, `s`/`del`/`strike`, `code`/`kbd`, `mark`, `br` and `a href` draw as what they mean GFM's filtered tags (`script`, `style`, `title`, `textarea`, `iframe`, `xmp`, `noembed`, `noframes`, `plaintext`) show as text, and other tags, hyphenated names too, vanish, leaving their text; a tag's name runs to white space or `/`, as HTML5 reads it; attribute values split on ASCII whitespace alone and decode as HTML decodes them; each Markdown container is the element GitHub writes (`em`, `strong`, `del`, `a`), on one stack with the tags and repaired as HTML5 repairs: an end tag closes the innermost element of its name and all above it, of which only formatting elements (`a`, `b`, `code`, `em`, `i`, `s`, `strike`, `strong`, `u`) reopen, a new `a` ends the open one and an `a` without `href` links nothing; other tags are not tracked, and `
` breaks as `
` does; and a footnote reference is its number in superscript, numbered by first reference, as its definition is; one `~` still strikes. At the root, blocks read as GitHub shows them: a quote whose first line is plain text reading `[!NOTE]`, `[!TIP]`, `[!IMPORTANT]`, `[!WARNING]` or `[!CAUTION]` in any case, after escapes and references, spaces and tabs around it, with more after it, is an alert under its title (Important in the palette's violet, `syntax.keyword`, read at 4.5:1); a paragraph that is `[toc]` alone, as Typora reads it, lists every heading by depth, and a press on one reveals it as a link press does (`MarkdownDocument`'s `reveal`), the heading found where `CodeEditor` anchors carried it through each edit since the read, gone if an edit or an undo took it, and a secondary press acts on press, since a block writing back moves the list; front matter shows in a box without its fences; an HTML block shows its text with the inline tags above, white space collapsed and owed as a browser lays it, block elements breaking lines and closing what opened inside them, HTML5's start tags ending an open `p`, `fieldset` and `menu` too, and an `li` start an `li`, a `dd` or `dt` start either, as HTML5 ends them, comments dropped, the filtered tags shown as text, and an unclosed tag dropping the rest; a rule is a 2px `border_strong` line; bullets go •, ◦, ▪ by list depth, ordered lists counted. `MarkdownDocument` holds a whole file in one `CodeEditor` (text and undo, colored by `CodeEditor::highlighter` with `markdown_highlights`): visual draws the file's top-level blocks in a gpui `list`, a pressed block opening as its source in a `TextInput` whose typing is the document's text at once and whose write-back is one undo step; source is the editor; preview draws without presses. A written-back block, a mode switch or a new text is read at once up to 128 KiB, longer ones on the background executor; typing in source or split reads 300 ms after the last key, off the main thread (markdown-rs grows with the square of a paragraph's lines: 40,000 lines take 0.9 s). Texts past `LARGEST_READ` (2 MiB) are never read: no blocks, no outline. A new read keeps the list's blocks alike at both ends. One caret serves every mode: the editor's selection, which a written-back block moves; `set_caret` and `set_top_line` set caret and view apart; a top line asked (numbered, so a late frame callback finishes only its own ask; new text places it again, clamped to the text as it then is) waits for the read, lands on its block, then a frame later at its share of the block's height; `reveal` is such an ask with the caret at its line; a switch between source and the list keeps the top line, one between visual and preview keeps the list's scroll as it is. A block opens only when the read is of the text as it is now. A pressed block keeps its identity across the write-back of the one before it. Blocks are Tab stops that Enter or Space opens; preview takes no presses, undo or redo. `CodeEditor` keeps at most 64 MiB of undo and redo text, dropping the oldest undo and then the farthest redo after every record, composition, undo and redo. `BlockData::from_markdown` and its export still read with `pulldown-cmark` 0.13 (MIT, default features off); it adds GitHub's alerts, a callout's form, and reads each field's inline Markdown from the source by offset, as written. - Pictures: `image` 0.25 (MIT OR Apache-2.0), the crate gpui decodes with, default features off; it turns decoded frames and rims map tiles. - Math and diagrams: RaTeX 0.1.14 (`ratex-parser`, `ratex-layout`, `ratex-svg` with `embed-fonts`, `ratex-types`; MIT, KaTeX's fonts OFL) typesets `Latex` to SVG with outlined glyphs; `mermaid-rs-renderer` 0.3.1 (MIT, default features off) draws `Diagram`. Both go through gpui's `SvgRenderer` at the window's scale, loaded as gpui assets off the main thread; `usvg` 0.46, gpui's own, reads a diagram's size. A RaTeX or Mermaid panic on parsed input becomes the element's error. Each element holds its picture through `primitives::held`: a new source, or the element leaving the window, removes the old asset from gpui's cache and drops its image from the atlas after the frame. - Maps: Natural Earth's 110m countries (public domain). `assets/maps/countries.geojson`, trimmed by `scripts/countries.py` to an ISO code, a name and positions to 0.01°, backs `maps::WorldMap`; the gallery's tiles are cut from the same file, z0 to z3, by `scripts/tiles.py` with Pillow. diff --git a/src/documents/document/edit.rs b/src/documents/document/edit.rs index a86d6a3..e5ebab9 100644 --- a/src/documents/document/edit.rs +++ b/src/documents/document/edit.rs @@ -12,27 +12,8 @@ use crate::{ forms::{InputEvent, TextInput}, }; -/// The one edit from `old` to `new`, by shared ends. -pub(super) fn between(old: &str, new: &str) -> Option<(Range, usize)> { - let head: usize = old - .chars() - .zip(new.chars()) - .take_while(|(a, b)| a == b) - .map(|(ch, _)| ch.len_utf8()) - .sum(); - let room = old.len().min(new.len()) - head; - let mut tail = 0; - for (a, b) in old.chars().rev().zip(new.chars().rev()) { - if a != b || tail + a.len_utf8() > room { - break; - } - tail += a.len_utf8(); - } - (old != new).then(|| (head..old.len() - tail, new.len() - tail - head)) -} - /// Where byte `at` lies after `edit`, if it survives. -pub(super) fn moved(at: usize, edit: &Option<(Range, usize)>) -> Option { +fn moved(at: usize, edit: &Option<(Range, usize)>) -> Option { match edit { None => Some(at), Some((replaced, _)) if at < replaced.start => Some(at), @@ -200,15 +181,4 @@ mod tests { assert_eq!(super::moved(3, &edit), None, "inside is gone"); assert_eq!(super::moved(7, &None), Some(7)); } - - #[test] - fn two_texts_part_at_their_shared_ends() { - assert_eq!(super::between("abc", "abc"), None); - assert_eq!(super::between("before\nB", "## B\nB"), Some((0..6, 4))); - assert_eq!(super::between("ab", "aXb"), Some((1..1, 1))); - assert_eq!(super::between("aa", "aaa"), Some((2..2, 1))); - assert_eq!(super::between("aXYb", "ab"), Some((1..3, 0))); - assert_eq!(super::between("é😄", "é"), Some((2..6, 0))); - assert_eq!(super::between("x😄", "y😄"), Some((0..1, 1))); - } } diff --git a/src/documents/document/mod.rs b/src/documents/document/mod.rs index b30387b..0b524e5 100644 --- a/src/documents/document/mod.rs +++ b/src/documents/document/mod.rs @@ -316,6 +316,9 @@ impl MarkdownDocument { let old = self.parsed.blocks.len(); self.list .splice(head..old - tail, read.blocks.len() - head - tail); + let headings: Vec = read.headings.iter().map(|heading| heading.at).collect(); + self.editor + .update(cx, |editor, _| editor.set_anchors(headings)); self.parsed = Arc::new(read); cx.emit(DocumentEvent::Parsed); cx.notify(); diff --git a/src/documents/document/place.rs b/src/documents/document/place.rs index 8e586f9..e0c0a16 100644 --- a/src/documents/document/place.rs +++ b/src/documents/document/place.rs @@ -1,11 +1,6 @@ -use std::sync::Arc; - use gpui::{App, Context, Focusable as _, ListOffset, ScrollStrategy, Window, px}; -use super::{ - MarkdownDocument, Placement, - edit::{between, moved}, -}; +use super::{MarkdownDocument, Placement}; use crate::documents::{MarkdownMode, modes::joint}; /// Line and column, from zero, of byte `at` in `text`. @@ -194,24 +189,31 @@ impl MarkdownDocument { .saturating_sub(1) } - /// Reveals the pressed heading, moved by the edit since. + /// Reveals the pressed heading where the edits since carried it. pub(super) fn reveal_at(&mut self, at: usize, window: &mut Window, cx: &mut Context) { - if !self.parsed.headings.iter().any(|heading| heading.at == at) { + let headings = &self.parsed.headings; + let Some(index) = headings.iter().position(|heading| heading.at == at) else { return log::warn!("markdown document: a heading read away"); - } - // The heading list drew from this read. - let drawn = Arc::clone(&self.parsed); - if self.commit(cx).is_some() || !self.read_now(cx) { + }; + self.commit(cx); + let anchors = self.editor.read(cx).anchors(); + let Some(found) = *anchors.get(index).expect("an anchor per heading read") else { + return log::warn!("markdown document: the pressed heading changed as one wrote"); + }; + if !self.read_now(cx) { self.reparse(true, cx); } if !self.read_now(cx) { return log::warn!("markdown document: a heading pressed while the text is read again"); } - let edit = between(&drawn.text, self.editor.read(cx).text()); - let headings = &self.parsed.headings; - let Some(found) = moved(at, &edit).filter(|at| headings.iter().any(|h| h.at == *at)) else { - return log::warn!("markdown document: the pressed heading changed as one wrote"); - }; + if !self + .parsed + .headings + .iter() + .any(|heading| heading.at == found) + { + return log::warn!("markdown document: the pressed heading reads as no heading now"); + } let line = self.editor.read(cx).buffer.line_of(found); self.reveal(line, window, cx); } diff --git a/src/documents/document/tests/toc.rs b/src/documents/document/tests/toc.rs index 7411753..d5ed070 100644 --- a/src/documents/document/tests/toc.rs +++ b/src/documents/document/tests/toc.rs @@ -132,3 +132,59 @@ fn a_press_while_the_text_waits_to_be_read_finds_the_heading(cx: &mut TestAppCon (26, 0) ); } + +/// Makes `edits` while the text waits, caret at the top. +fn edit_waiting<'a>( + text: &str, + edits: Vec<(std::ops::Range, String)>, + cx: &'a mut TestAppContext, +) -> (Entity, &'a mut VisualTestContext) { + let (document, cx) = open(text, MarkdownMode::Split, cx); + document.update(cx, |document, cx| { + document + .editor + .update(cx, |editor, cx| editor.edit(edits, cx)); + document.set_caret(0, 0, cx); + }); + frames(cx); + assert!(!document.read_with(cx, |document, cx| document.read_now(cx))); + (document, cx) +} + +fn caret(document: &Entity, cx: &mut VisualTestContext) -> (usize, usize) { + document.read_with(cx, |document, cx| document.caret(cx)) +} + +#[gpui::test] +fn a_twin_written_right_at_the_heading_goes_before_it(cx: &mut TestAppContext) { + let edits = vec![(7..7, "## B\n\n".to_string())]; + let (document, cx) = edit_waiting("[toc]\n\n## B\n\ntext\n", edits, cx); + press_entry(0, Modifiers::none(), cx); + assert_eq!(caret(&document, cx), (4, 0)); +} + +#[gpui::test] +fn adjacent_twins_keep_who_was_deleted(cx: &mut TestAppContext) { + let twins = "[toc]\n\n## B\n\n## B\n\ntext\n"; + let (document, cx) = edit_waiting(twins, vec![(7..13, String::new())], cx); + press_entry(0, Modifiers::none(), cx); + assert_eq!( + caret(&document, cx), + (0, 0), + "the deleted one moves nothing" + ); + press_entry(1, Modifiers::none(), cx); + assert_eq!(caret(&document, cx), (2, 0), "the kept one moved up"); +} + +#[gpui::test] +fn a_heading_between_two_edits_stays_found(cx: &mut TestAppContext) { + let text = "before\n\n[toc]\n\n# A\n\nafter\n"; + let edits = vec![ + (0..0, "start\n".to_string()), + (text.len()..text.len(), "end\n".to_string()), + ]; + let (document, cx) = edit_waiting(text, edits, cx); + press_entry(0, Modifiers::none(), cx); + assert_eq!(caret(&document, cx), (5, 0)); +} diff --git a/src/documents/tree/blocks.rs b/src/documents/tree/blocks.rs index 80027a9..797bbbf 100644 --- a/src/documents/tree/blocks.rs +++ b/src/documents/tree/blocks.rs @@ -99,6 +99,7 @@ impl Reader<'_> { rest = &rest[at..]; if let Some(comment) = rest.strip_prefix("").map_or("", |(_, after)| after); + run.shortcodes.split(); continue; } let opens = @@ -116,10 +117,7 @@ impl Reader<'_> { let (written, after) = rest.split_at(end); rest = after; match html::tag(written) { - Some(tag) if html::filtered(&tag.name) => { - run.filter(&tag); - run.spaced(&html::text(written)); - } + Some(tag) if html::filtered(&tag.name) => run.words(written), // A block closes what opened inside it. Some(tag) if html::breaks(&tag.name) => { run.line(); @@ -127,12 +125,18 @@ impl Reader<'_> { true => run.end(&tag.name), false => { run.implied(&tag.name); - if tag.name != "hr" { - run.start(&tag.name, None, None); + match tag.name == "hr" { + true => run.shortcodes.split(), + false => run.start(&tag.name, None, None), } } } } + // It ends a `p` but lays no block. + Some(tag) if !tag.closing && html::closes_p(&tag.name) => { + run.implied(&tag.name); + run.html(written); + } // A line's end drops its space. Some(tag) if tag.closing || tag.name == "br" => { run.owed = run.owed.filter(|_| tag.name != "br"); @@ -142,7 +146,7 @@ impl Reader<'_> { run.pay(); run.html(written); } - None => {} + None => run.shortcodes.split(), } } run.words(rest); @@ -153,11 +157,8 @@ impl Reader<'_> { impl Run { /// HTML text: references decoded, white space collapsed. fn words(&mut self, written: &str) { - let decoded = html::text(written); - match self.reads_emoji() { - true => self.spaced(&html::emoji(&decoded)), - false => self.spaced(&decoded), - } + let shown = self.shown(&html::text(written)); + self.spaced(&shown); } /// Text with its white space collapsed. @@ -215,8 +216,8 @@ impl Run { if let Some(item) = found { self.end(&item); } - // A table start closes it, so it is in scope. - if name != "tr" && self.count("p") > 0 { + if html::closes_p(name) && self.count("p") > 0 { + self.line(); self.end("p"); } } @@ -417,18 +418,50 @@ mod tests { } #[test] - fn filtered_tags_keep_shortcodes_and_names_end_as_html5_ends_them() { - let block = html("").expect("text"); - assert_eq!(block.text, ""); - assert_eq!(html("
:smile:
").expect("text").text, "😄"); - let attribute = html("a c").expect("text"); - assert_eq!(attribute.text, "a c"); - let body = html("a :smile:").expect("text"); - assert_eq!(body.text, "a 😄"); + fn filtered_tags_are_text_and_names_end_as_html5_ends_them() { + // GitHub's answers, `.work/R4.3-fix3/github-*.log`. + for (source, shown) in [ + ( + "
:smile:
", + " :smile:", + ), + ( + "
:smile:
", + " 😄", + ), + ( + "
:smile:
", + " 😄", + ), + ( + "
:smile:", + "a :smile:", + ), + ( + "a :smile:", + "a 😄", + ), + ] { + assert_eq!(line(source).text, shown, "{source:?}"); + } +} diff --git a/src/editor/anchors.rs b/src/editor/anchors.rs index 1eb8b03..9214995 100644 --- a/src/editor/anchors.rs +++ b/src/editor/anchors.rs @@ -1,6 +1,6 @@ use std::ops::Range; -use super::state::Marks; +use super::state::{CodeEditor, Marks}; /// Where `offset` lands after `edits`, sorted and apart, each a replaced range and the length written; none when an edit replaced it. fn moved(offset: usize, edits: &[(Range, usize)]) -> Option { @@ -17,6 +17,21 @@ fn moved(offset: usize, edits: &[(Range, usize)]) -> Option { Some(at as usize) } +/// Where the character at `offset` lands; text written at it goes before. +fn carried(offset: usize, edits: &[(Range, usize)]) -> Option { + let mut at = offset as isize; + for (range, written) in edits { + if offset < range.start { + break; + } + if offset < range.end { + return None; + } + at += *written as isize - range.len() as isize; + } + Some(at as usize) +} + /// A range through `edits`; none when an edit cut into it. fn moved_range(range: &Range, edits: &[(Range, usize)]) -> Option> { Some(moved(range.start, edits)?..moved(range.end, edits)?) @@ -43,6 +58,9 @@ pub(crate) fn shift(marks: &mut Marks, edits: &[(Range, usize)]) { ghost.offset = moved(ghost.offset, edits)?; Some(ghost) }); + for anchor in &mut marks.anchors { + *anchor = anchor.and_then(|at| carried(at, edits)); + } } /// Drops the owner's offsets when the whole text changes; they named the old one. @@ -51,6 +69,27 @@ pub(crate) fn clear(marks: &mut Marks) { marks.backgrounds.clear(); marks.hints.clear(); marks.ghost = None; + marks.anchors.fill(None); +} + +impl CodeEditor { + /// Offsets the editor carries through each edit. + pub fn set_anchors(&mut self, offsets: impl IntoIterator) { + let text = self.buffer.text(); + let whole = |at: usize| { + let fits = text.is_char_boundary(at); + if !fits { + log::error!("code editor: anchor {at} splits a character"); + } + fits.then_some(at) + }; + self.marks.anchors = offsets.into_iter().map(whole).collect(); + } + + /// Where each anchor is now; none once an edit took it. + pub fn anchors(&self) -> &[Option] { + &self.marks.anchors + } } /// Whether `range` runs forward between whole characters of `text`. @@ -62,7 +101,7 @@ pub(crate) fn fits(text: &str, range: &Range) -> bool { #[cfg(test)] mod tests { - use super::{fits, moved}; + use super::{carried, fits, moved}; #[test] fn offsets_ride_their_edits() { @@ -80,4 +119,13 @@ mod tests { assert_eq!(moved(8, &edits), Some(10)); assert!(fits("héllo", &(1..3)) && !fits("héllo", &cut) && !fits("ab", &(1..9))); } + + #[test] + fn anchors_go_after_text_written_at_them() { + let edits = [(2..4, 1), (6..6, 3)]; + assert_eq!(carried(2, &edits), None, "its character replaced"); + assert_eq!(carried(4, &edits), Some(3), "just past a replace"); + assert_eq!(carried(6, &edits), Some(8), "after an insertion at it"); + assert_eq!(carried(1, &edits), Some(1)); + } } diff --git a/src/editor/state.rs b/src/editor/state.rs index 1fe77f2..0051665 100644 --- a/src/editor/state.rs +++ b/src/editor/state.rs @@ -84,6 +84,8 @@ pub(crate) struct Marks { pub git: Vec<(usize, GitMark)>, pub breakpoints: BTreeSet, pub chat: Option, + /// The owner's offsets; an edit over one drops it. + pub anchors: Vec>, } /// The text and cursors one undo step returns to.