diff --git a/crates/helm-bench/Cargo.toml b/crates/helm-bench/Cargo.toml index 6185811..26a0125 100644 --- a/crates/helm-bench/Cargo.toml +++ b/crates/helm-bench/Cargo.toml @@ -66,3 +66,7 @@ harness = false [[bench]] name = "vim_objects" harness = false + +[[bench]] +name = "typing" +harness = false diff --git a/crates/helm-bench/benches/typing.rs b/crates/helm-bench/benches/typing.rs new file mode 100644 index 0000000..80e7756 --- /dev/null +++ b/crates/helm-bench/benches/typing.rs @@ -0,0 +1,210 @@ +//! Typing group benchmarks for `helm-editor` (T-112), gated by the `bench` +//! CI job against `budgets.toml`. NF-1 gives a keypress 5 ms from input to +//! pixel, and deciding whether an edit joins the open undo step is on that +//! path. A decision that copied or read the text would show up here. + +use std::hint::black_box; +use std::time::Duration; + +use criterion::{Criterion, criterion_group, criterion_main}; +use helm_editor::{ + CommandRegistry, Dispatcher, Editor, Key, KeyEvent, KeySequence, Keystroke, Modifiers, + Selection, Selections, UndoGrouping, vscode, +}; +use helm_text::{Buffer, BufferId, BufferSet, FileFormat, LineEndings, TextBuffer}; + +/// Number of cursors in the many-cursor benchmark. +const CURSORS: usize = 1000; + +/// Size of the benchmark text: 10 MiB, cut down to a char boundary. +const TEXT_LEN: usize = 10 << 20; + +/// The chars the typing benchmarks cycle through: ASCII, a space, and +/// chars of 4, 3 and 2 bytes. +const TYPED: &str = "helm 😀中é"; + +/// The time between two keys: well under `Editor::TYPING_PAUSE`, so no +/// pause ends a step. +const KEY_GAP: Duration = Duration::from_millis(10); + +/// The same lines `benches/editor.rs` repeats: ASCII code mixed with é, +/// 中 and 😀, ending in both LF and CRLF. +const LINES: &str = concat!( + "fn main() {\n", + " let café = \"crème brûlée\";\r\n", + " // 中文注释: 编辑器\n", + " println!(\"{café} 😀 done\");\r\n", + " let emoji = ['😀', '中', 'é'];\n", + "}\r\n", + "\n", +); + +/// The largest char boundary of `text` at or below `byte`. +fn floor_boundary(text: &str, mut byte: usize) -> usize { + while !text.is_char_boundary(byte) { + byte -= 1; + } + byte +} + +/// 10 MiB of `LINES` repeated, cut at the last char boundary at or below +/// `TEXT_LEN`. +fn build_text() -> String { + let mut text = LINES.repeat(TEXT_LEN / LINES.len() + 1); + text.truncate(floor_boundary(&text, TEXT_LEN)); + text +} + +/// An editor on `id` with `selections`, under typing grouping. +fn typing_editor(id: BufferId, format: FileFormat, selections: &Selections) -> Editor { + let mut editor = Editor::new(id, format); + editor.set_selections(selections.clone()); + editor.set_undo_grouping(UndoGrouping::Typing); + editor +} + +/// One key event per key of `keys`, in `KeySequence` notation. +fn keys(keys: &str) -> Vec { + KeySequence::parse(keys) + .expect("valid keys") + .as_slice() + .iter() + .map(|&keystroke| KeyEvent::new(keystroke)) + .collect() +} + +/// One key event per char of `text`, each typing its char. +fn chars(text: &str) -> Vec { + text.chars() + .map(|c| KeyEvent::new(Keystroke::new(Key::Char(c), Modifiers::NONE))) + .collect() +} + +fn typing(c: &mut Criterion) { + let text = build_text(); + let mut set = BufferSet::new(); + let id = set.add(Buffer::from(text.as_str())); + let format = FileFormat { + bom: false, + line_endings: LineEndings::count(&text), + }; + let buffer = set.get(id).expect("just added"); + // One cursor at the start of each of 1,000 `fn main() {` lines spread + // evenly across the text, as `benches/cursor.rs` places them. + let repeats = buffer.len_lines() / LINES.lines().count() - 1; + let starts: Vec = (0..CURSORS) + .map(|i| { + let line = i * repeats / CURSORS * LINES.lines().count(); + let at = buffer.line_to_byte(line).expect("line in range"); + assert_eq!(buffer.slice(at..at + 2).as_deref(), Ok("fn")); + at + }) + .collect(); + let selections = Selections::new(starts.iter().map(|&at| Selection::cursor(at)).collect(), 0) + .expect("non-empty, primary in range"); + let middle = Selections::single(Selection::cursor(starts[CURSORS / 2])); + let typed: Vec = TYPED.chars().map(String::from).collect(); + + let mut group = c.benchmark_group("typing"); + + // Each benchmark moves its own clock on by `KEY_GAP` per key, so every + // run of keys is one step, and the undo takes the whole run back. The + // next edit drops the redo entry, so every iteration starts from the + // same text and selections. + let mut now = Duration::ZERO; + let mut editor = typing_editor(id, format, &middle); + group.bench_function("type_100_chars_undo_10mb", |b| { + b.iter(|| { + for c in typed.iter().cycle().take(100) { + now += KEY_GAP; + editor.set_time(now); + black_box( + editor + .insert(&mut set, black_box(c)) + .expect("buffer is in the set"), + ); + } + black_box(editor.undo(&mut set).expect("nothing blocks the undo")); + }) + }); + assert_eq!( + editor.selections(), + &middle, + "type_100_chars_undo_10mb ends where it began" + ); + + let mut now = Duration::ZERO; + let mut editor = typing_editor(id, format, &selections); + group.bench_function("type_10_chars_undo_1000_cursors_10mb", |b| { + b.iter(|| { + for c in typed.iter().cycle().take(10) { + now += KEY_GAP; + editor.set_time(now); + black_box( + editor + .insert(&mut set, black_box(c)) + .expect("buffer is in the set"), + ); + } + black_box(editor.undo(&mut set).expect("nothing blocks the undo")); + }) + }); + assert_eq!( + editor.selections(), + &selections, + "type_10_chars_undo_1000_cursors_10mb ends where it began" + ); + + // `hello`, two Backspaces, `lo world`, Enter and `x`, Left, then `y`: + // five steps, which five `cmd-z`s take back. + let dispatcher = Dispatcher::new(CommandRegistry::with_all_commands(), vscode::keymap()); + let mut state = dispatcher.key_state(); + let mut events = chars("hello"); + events.extend(keys("backspace backspace")); + events.extend(chars("lo world")); + events.extend(keys("enter")); + events.extend(chars("x")); + events.extend(keys("left")); + events.extend(chars("y")); + let undo = keys("cmd-z"); + let mut now = Duration::ZERO; + let mut editor = Editor::new(id, format); + editor.set_selections(middle.clone()); + group.bench_function("vscode_session_undo_10mb", |b| { + b.iter(|| { + for event in &events { + now += KEY_GAP; + editor.set_time(now); + black_box( + dispatcher + .dispatch(&mut state, black_box(event), &[], &mut editor, &mut set) + .expect("the command runs"), + ); + } + for _ in 0..5 { + now += KEY_GAP; + editor.set_time(now); + black_box( + dispatcher + .dispatch(&mut state, black_box(&undo[0]), &[], &mut editor, &mut set) + .expect("the command runs"), + ); + } + }) + }); + assert_eq!( + editor.selections(), + &middle, + "vscode_session_undo_10mb ends where it began" + ); + assert_eq!( + set.get(id).expect("in the set").to_string(), + text, + "the typing benchmarks end with the text they started with" + ); + + group.finish(); +} + +criterion_group!(benches, typing); +criterion_main!(benches); diff --git a/crates/helm-editor/src/dispatch.rs b/crates/helm-editor/src/dispatch.rs index 1429eb0..eb22762 100644 --- a/crates/helm-editor/src/dispatch.rs +++ b/crates/helm-editor/src/dispatch.rs @@ -492,6 +492,7 @@ impl Dispatcher { ) -> Result { let resolution = self.resolve(state, event, contexts); if let Resolution::Run(invocation) = &resolution { + editor.set_undo_grouping(self.keymap.undo_grouping()); self.registry.run(invocation, editor, set)?; } Ok(resolution) @@ -524,6 +525,7 @@ impl Dispatcher { let resolution = self.resolve(state, event, contexts); let requests = match &resolution { Resolution::Run(invocation) => { + editor.set_undo_grouping(self.keymap.undo_grouping()); self.registry.run_in(invocation, editor, set, session)? } _ => Vec::new(), diff --git a/crates/helm-editor/src/editor.rs b/crates/helm-editor/src/editor.rs index be999ac..fe385bb 100644 --- a/crates/helm-editor/src/editor.rs +++ b/crates/helm-editor/src/editor.rs @@ -223,6 +223,46 @@ pub struct Editor { /// The open undo group, if any, and the transaction its edits fold /// into once its first edit has applied one. group: Option>, + /// Who opens and closes undo groups (T-112). + grouping: UndoGrouping, + /// The time [`set_time`](Self::set_time) last gave. + now: Duration, + /// The open group's last edit's kind and time, when the open group is + /// a typing group. `None` while no group or an explicit one is open. + typing: Option, + /// Whether one of the nine moves changed the selections since the open + /// typing group's last edit. + moved: bool, +} + +/// A typing group's last edit (T-112). +#[derive(Clone, Copy, Debug)] +struct Last { + kind: Kind, + at: Duration, +} + +/// The kind of an editing command under [`UndoGrouping::Typing`] (T-112). +/// Every edit without one is an other edit. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Kind { + Typing, + Backward, + Forward, +} + +impl Kind { + /// The kind of a delete by `motion`. + fn of_delete(motion: Motion) -> Self { + match motion { + Motion::Left + | Motion::Up + | Motion::WordLeft + | Motion::LineStart + | Motion::TextStart => Self::Backward, + _ => Self::Forward, + } + } } /// An [`Editor`]'s identity (T-109). Vim's `.` record belongs to the @@ -279,6 +319,10 @@ impl Clone for Editor { undone: self.undone.clone(), goals: self.goals.clone(), group: self.group, + grouping: self.grouping, + now: self.now, + typing: self.typing, + moved: self.moved, } } } @@ -311,6 +355,15 @@ struct Record { after: Selections, } +/// How a typing or deleting edit takes part in typing groups (T-112). +#[derive(Clone, Copy, Debug)] +struct Step { + kind: Kind, + /// Whether the edit always starts a typing group: a newline, or a + /// delete that takes a line break. + starts: bool, +} + /// Which way a command looks from each selection's head. #[derive(Clone, Copy, PartialEq, Eq)] enum Direction { @@ -334,6 +387,10 @@ impl Editor { undone: Vec::new(), goals: Vec::new(), group: None, + grouping: UndoGrouping::Explicit, + now: Duration::ZERO, + typing: None, + moved: false, } } @@ -361,6 +418,9 @@ impl Editor { /// here; the next command clamps them. pub fn set_selections(&mut self, selections: Selections) { self.goals.clear(); + if selections != self.selections { + self.moved = true; + } self.selections = selections; } @@ -375,7 +435,7 @@ impl Editor { set: &mut BufferSet, text: &str, ) -> Result, EditorError> { - self.replace_each(set, text) + self.replace_each(set, text, false) } /// Inserts a line break at every selection, the same way @@ -383,7 +443,7 @@ impl Editor { /// [`FileFormat::newline`] of this editor's format. No indentation is /// added. pub fn newline(&mut self, set: &mut BufferSet) -> Result, EditorError> { - self.replace_each(set, self.format.newline().as_str()) + self.replace_each(set, self.format.newline().as_str(), true) } /// Backspace at every selection. A non-empty selection deletes its @@ -400,7 +460,7 @@ impl Editor { &mut self, set: &mut BufferSet, ) -> Result, EditorError> { - self.delete_each(set, |buffer, selection| { + self.delete_each(set, Kind::Backward, |buffer, selection| { delete_range(buffer, selection, Direction::Backward) }) } @@ -413,7 +473,7 @@ impl Editor { &mut self, set: &mut BufferSet, ) -> Result, EditorError> { - self.delete_each(set, |buffer, selection| { + self.delete_each(set, Kind::Forward, |buffer, selection| { delete_range(buffer, selection, Direction::Forward) }) } @@ -463,7 +523,7 @@ impl Editor { } selections }; - Ok(self.selections != old) + Ok(self.moved_from(&old)) } /// Replaces the selections with every match of the primary's text @@ -506,7 +566,7 @@ impl Editor { } None => clamped, }; - Ok(self.selections != old) + Ok(self.moved_from(&old)) } /// Adds a cursor on the line above every selection's head (ED-3, "add @@ -542,7 +602,7 @@ impl Editor { pub fn undo(&mut self, set: &mut BufferSet) -> Result, EditorError> { let id = set.undo(self.buffer)?; self.goals.clear(); - self.group = None; + self.end_undo_group(); if let Some(record) = id.and_then(|id| self.history.get(&id)) { self.selections = record.before.clone(); self.undone.push(record.id); @@ -560,7 +620,7 @@ impl Editor { pub fn redo(&mut self, set: &mut BufferSet) -> Result, EditorError> { let id = set.redo(self.buffer)?; self.goals.clear(); - self.group = None; + self.end_undo_group(); if let Some(record) = id.and_then(|id| self.history.get(&id)) { self.selections = record.after.clone(); self.undone.retain(|&undone| undone != record.id); @@ -581,7 +641,9 @@ impl Editor { /// so cursors that land on one offset merge. The primary is the /// selection the old primary became. pub fn move_cursors(&mut self, set: &BufferSet, motion: Motion) -> Result { - self.move_heads(set, motion, false) + let changed = self.move_heads(set, motion, false)?; + self.moved |= changed; + Ok(changed) } /// Extends every selection by `motion` (T-107): each head moves where @@ -598,7 +660,9 @@ impl Editor { set: &BufferSet, motion: Motion, ) -> Result { - self.move_heads(set, motion, true) + let changed = self.move_heads(set, motion, true)?; + self.moved |= changed; + Ok(changed) } /// Deletes from every cursor to where `motion` takes it (T-107), in one @@ -619,7 +683,7 @@ impl Editor { motion: Motion, ) -> Result, EditorError> { let mut reads = Reads::default(); - self.delete_each(set, |buffer, selection| { + self.delete_each(set, Kind::of_delete(motion), |buffer, selection| { if !selection.is_empty() { return Some(selection.range()); } @@ -640,7 +704,7 @@ impl Editor { &mut self.selections, Selections::single(Selection::new(0, buffer.len_bytes())), ); - Ok(self.selections != old) + Ok(self.moved_from(&old)) } /// VS Code's Escape (T-107). With more than one selection, keeps only @@ -658,19 +722,21 @@ impl Editor { Selection::cursor(primary.head) }; let old = std::mem::replace(&mut self.selections, Selections::single(collapsed)); - Ok(self.selections != old) + Ok(self.moved_from(&old)) } /// Opens an undo group (T-108), as the type docs describe. If a group /// is already open, it ends first and a new one starts, so the next /// edit is a new undo step. pub fn begin_undo_group(&mut self) { + self.typing = None; self.group = Some(None); } /// Closes the open undo group (T-108), explicit or typing (T-112). /// Returns whether one was open. The next edit is a new undo step. pub fn end_undo_group(&mut self) -> bool { + self.typing = None; self.group.take().is_some() } @@ -688,17 +754,16 @@ impl Editor { /// different value from the current one ends any open group, explicit /// or typing. The same value changes nothing. A new editor has /// [`UndoGrouping::Explicit`]. - #[expect( - unused_variables, - reason = "T-112 interface stub; the implementation deletes this" - )] pub fn set_undo_grouping(&mut self, grouping: UndoGrouping) { - todo!() + if grouping != self.grouping { + self.grouping = grouping; + self.end_undo_group(); + } } /// Who opens and closes this editor's undo groups (T-112). pub fn undo_grouping(&self) -> UndoGrouping { - todo!() + self.grouping } /// The time of the edits that follow (T-112), measured from any fixed @@ -706,12 +771,8 @@ impl Editor { /// it. The editor never reads a clock: it compares this with the time /// of a typing group's last edit, under [`UndoGrouping::Typing`] only. /// Until the first call, every edit happens at time zero. - #[expect( - unused_variables, - reason = "T-112 interface stub; the implementation deletes this" - )] pub fn set_time(&mut self, now: Duration) { - todo!() + self.now = now; } } @@ -723,13 +784,18 @@ impl Editor { }) } - /// Replaces every selection with `text` in one transaction. + /// Replaces every selection with `text` in one transaction, as typing. + /// `newline` marks [`newline`](Self::newline), which always starts a + /// typing group. fn replace_each( &mut self, set: &mut BufferSet, text: &str, + newline: bool, ) -> Result, EditorError> { - let before = clamp(self.buffer_in(set)?, &self.selections); + let buffer = self.buffer_in(set)?; + self.note_other_moves(); + let before = clamp(buffer, &self.selections); self.goals.clear(); self.selections = before.clone(); if text.is_empty() && before.as_slice().iter().all(Selection::is_empty) { @@ -750,17 +816,24 @@ impl Editor { removed += range.len(); } let after = normal(cursors, before.primary_index()); - Ok(Some(self.apply(set, transaction, before, after))) + let step = Step { + kind: Kind::Typing, + starts: newline, + }; + Ok(Some(self.apply_step(set, transaction, before, after, step))) } /// Deletes the range `range_of` gives each selection, in one - /// transaction. `None` deletes nothing at that selection. + /// transaction of kind `kind`. `None` deletes nothing at that + /// selection. fn delete_each( &mut self, set: &mut BufferSet, + kind: Kind, mut range_of: impl FnMut(&Buffer, Selection) -> Option>, ) -> Result, EditorError> { let buffer = self.buffer_in(set)?; + self.note_other_moves(); self.goals.clear(); let before = clamp(buffer, &self.selections); self.selections = before.clone(); @@ -803,18 +876,105 @@ impl Editor { }) .collect(); let after = normal(cursors, before.primary_index()); + // Only a delete that may join a typing group needs the line-break + // rule, so explicit grouping skips the lookups. + let starts = self.typing.is_some() + && joined.iter().any(|range| { + buffer.byte_to_line(range.start).ok() != buffer.byte_to_line(range.end).ok() + }); let transaction = joined .into_iter() .map(|range| Edit::delete(self.buffer, range)) .collect(); - Ok(Some(self.apply(set, transaction, before, after))) + let step = Step { kind, starts }; + Ok(Some(self.apply_step(set, transaction, before, after, step))) + } + + /// Whether the selections changed from `old`, recording a move if + /// they did (T-112). Each of the nine moves reports through this or + /// sets `moved` itself. + fn moved_from(&mut self, old: &Selections) -> bool { + let changed = self.selections != *old; + self.moved |= changed; + changed + } + + /// Under an open typing group, records a move if the selections differ + /// from those just after the group's last edit (T-112). That catches + /// changes made outside the nine moves, such as Vim's motions. It runs + /// before clamping, so clamping is never a move. + fn note_other_moves(&mut self) { + if self.typing.is_none() || self.moved { + return; + } + if let Some(Some(id)) = self.group + && self + .history + .get(&id) + .is_some_and(|record| record.after != self.selections) + { + self.moved = true; + } + } + + /// Applies `transaction` as an other edit (T-112), such as one of + /// Vim's. Under [`UndoGrouping::Typing`] it first ends an open typing + /// group, so the edit is its own step and leaves no group open. An + /// explicit group stays open and the edit folds into it. + fn apply( + &mut self, + set: &mut BufferSet, + transaction: Transaction, + before: Selections, + after: Selections, + ) -> TransactionId { + if self.grouping == UndoGrouping::Typing && self.typing.is_some() { + // An other edit ends the typing group and leaves none open. + self.end_undo_group(); + } + self.apply_in_group(set, transaction, before, after) + } + + /// Applies a typing or deleting edit. Under [`UndoGrouping::Typing`] + /// with no explicit group open, it first decides by the "Typing + /// groups" rules whether the edit joins the open typing group or + /// starts a new one, and then records it as the group's last edit. + fn apply_step( + &mut self, + set: &mut BufferSet, + transaction: Transaction, + before: Selections, + after: Selections, + step: Step, + ) -> TransactionId { + let explicit = self.group.is_some() && self.typing.is_none(); + if self.grouping != UndoGrouping::Typing || explicit { + return self.apply_in_group(set, transaction, before, after); + } + let joins = !step.starts + && !self.moved + && self.typing.is_some_and(|last| { + last.kind == step.kind + // A time earlier than the last edit's is no pause. + && self.now.saturating_sub(last.at) < Self::TYPING_PAUSE + }); + if !joins { + self.group = Some(None); + } + let id = self.apply_in_group(set, transaction, before, after); + self.typing = Some(Last { + kind: step.kind, + at: self.now, + }); + self.moved = false; + id } /// Applies `transaction`, which this editor built from `before`, and /// moves to `after`. In an open undo group whose first edit is done, /// amends the group's transaction instead, and applies a new one only /// if `amend` refuses. - fn apply( + fn apply_in_group( &mut self, set: &mut BufferSet, transaction: Transaction, @@ -921,7 +1081,7 @@ impl Editor { } } self.selections = normal(list, primary); - Ok(self.selections != old) + Ok(self.moved_from(&old)) } } diff --git a/crates/helm-editor/src/keymap.rs b/crates/helm-editor/src/keymap.rs index b425b63..66ff496 100644 --- a/crates/helm-editor/src/keymap.rs +++ b/crates/helm-editor/src/keymap.rs @@ -233,6 +233,8 @@ pub struct Keymap { /// the keystroke, in the order they were added. Resolving a key only /// looks at one of these lists, not every binding. by_first_key: HashMap>, + /// The undo grouping the dispatcher gives each editor (T-112). + grouping: UndoGrouping, } impl Keymap { @@ -261,6 +263,7 @@ impl Keymap { modes, bindings: Vec::new(), by_first_key: HashMap::new(), + grouping: UndoGrouping::Explicit, }) } @@ -308,18 +311,14 @@ impl Keymap { /// [`UndoGrouping`] [`Dispatcher::dispatch`](crate::Dispatcher::dispatch) /// gives each editor before running a command. [`Keymap::new`] gives /// [`UndoGrouping::Explicit`]. - #[expect( - unused_variables, - unused_mut, - reason = "T-112 interface stub; the implementation deletes this" - )] pub fn with_undo_grouping(mut self, grouping: UndoGrouping) -> Self { - todo!() + self.grouping = grouping; + self } /// This keymap's undo grouping (T-112). pub fn undo_grouping(&self) -> UndoGrouping { - todo!() + self.grouping } /// Whether any mode's typing is [`Typing::Count`]. diff --git a/crates/helm-editor/src/vscode.rs b/crates/helm-editor/src/vscode.rs index cb0efff..033cdbc 100644 --- a/crates/helm-editor/src/vscode.rs +++ b/crates/helm-editor/src/vscode.rs @@ -90,8 +90,9 @@ pub fn keymap() -> Keymap { ("cmd-backspace", cursor::DELETE_LINE_START), ("cmd-delete", cursor::DELETE_LINE_END), ]; - let mut keymap = - Keymap::new(NAME, vec![Mode::new(MODE, Typing::Insert)]).expect("one mode, no duplicates"); + let mut keymap = Keymap::new(NAME, vec![Mode::new(MODE, Typing::Insert)]) + .expect("one mode, no duplicates") + .with_undo_grouping(crate::UndoGrouping::Typing); for (keys, command) in BINDINGS { let binding = Binding::run(keys, command).expect("the bindings above parse"); keymap.bind(binding).expect("bindings name no mode"); diff --git a/crates/helm-editor/tests/typing_group_properties.rs b/crates/helm-editor/tests/typing_group_properties.rs index 64ee15d..11a0d4e 100644 --- a/crates/helm-editor/tests/typing_group_properties.rs +++ b/crates/helm-editor/tests/typing_group_properties.rs @@ -293,7 +293,6 @@ proptest! { /// Typing grouping changes only undo: the texts and selections after /// every op are the same as under explicit grouping. #[test] - #[ignore = "T-112: not implemented yet"] fn grouping_never_changes_the_edits((text0, cursors, ops) in case(true, true)) { let (mut set_a, mut typing) = editor(&text0, &cursors, UndoGrouping::Typing); let (mut set_b, mut explicit) = editor(&text0, &cursors, UndoGrouping::Explicit); @@ -309,7 +308,6 @@ proptest! { /// Undo steps start where the rules say, and undo and redo walk them. #[test] - #[ignore = "T-112: not implemented yet"] fn steps_start_where_the_rules_say((text0, cursors, ops) in case(false, false)) { let (marks, last) = oracle(&text0, &cursors, &ops); let (mut set, mut e) = editor(&text0, &cursors, UndoGrouping::Typing); @@ -323,7 +321,6 @@ proptest! { /// Under explicit grouping with no groups, every edit that applies a /// transaction is one step, whatever the time says. #[test] - #[ignore = "T-112: not implemented yet"] fn explicit_grouping_makes_each_edit_a_step((text0, cursors, ops) in case(true, false)) { let (mut set, mut e) = editor(&text0, &cursors, UndoGrouping::Explicit); let mut now = Duration::ZERO; @@ -342,7 +339,6 @@ proptest! { /// opened and closed in between: each is one step, and typing groups /// start again after it. #[test] - #[ignore = "T-112: not implemented yet"] fn explicit_groups_inside_typing_grouping((text0, cursors, ops) in case(false, true)) { let (marks, last) = oracle(&text0, &cursors, &ops); let (mut set, mut e) = editor(&text0, &cursors, UndoGrouping::Typing); diff --git a/crates/helm-editor/tests/typing_groups.rs b/crates/helm-editor/tests/typing_groups.rs index 1075526..2300876 100644 --- a/crates/helm-editor/tests/typing_groups.rs +++ b/crates/helm-editor/tests/typing_groups.rs @@ -80,7 +80,6 @@ fn at(millis: u64) -> Duration { } #[test] -#[ignore = "T-112: not implemented yet"] fn the_default_grouping_is_explicit_and_unchanged() { assert_eq!(UndoGrouping::default(), UndoGrouping::Explicit); let (mut set, mut e) = editor_with("", &[Selection::cursor(0)], UndoGrouping::Explicit); @@ -91,7 +90,6 @@ fn the_default_grouping_is_explicit_and_unchanged() { } #[test] -#[ignore = "T-112: not implemented yet"] fn a_typed_word_undoes_and_redoes_in_one_step() { let (mut set, mut e) = typing("x", &[Selection::cursor(1)]); assert_eq!(e.undo_grouping(), UndoGrouping::Typing); @@ -115,7 +113,6 @@ fn a_typed_word_undoes_and_redoes_in_one_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn three_cursors_in_crlf_type_as_one_step() { let (mut set, mut e) = typing( "a\r\nb\r\nc", @@ -134,7 +131,6 @@ fn three_cursors_in_crlf_type_as_one_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn cursors_that_merge_during_a_run_keep_the_step() { let (mut set, mut e) = typing("xabcd", &[Selection::cursor(3), Selection::cursor(5)]); e.delete_backward(&mut set).unwrap().expect("applied"); @@ -151,7 +147,6 @@ fn cursors_that_merge_during_a_run_keep_the_step() { type MoveFn = fn(&mut Editor, &BufferSet); #[test] -#[ignore = "T-112: not implemented yet"] fn every_kind_of_move_ends_the_step() { let start = "ab cd\nef"; let cases: [(&str, Vec, MoveFn); 11] = [ @@ -221,7 +216,6 @@ fn every_kind_of_move_ends_the_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn a_move_that_changes_nothing_keeps_the_step() { let (mut set, mut e) = typing("", &[Selection::cursor(0)]); type_chars(&mut set, &mut e, "a"); @@ -235,7 +229,6 @@ fn a_move_that_changes_nothing_keeps_the_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn a_move_and_a_move_back_end_the_step() { let (mut set, mut e) = typing("", &[Selection::cursor(0)]); type_chars(&mut set, &mut e, "a"); @@ -250,7 +243,6 @@ fn a_move_and_a_move_back_end_the_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn switching_between_typing_and_deleting_ends_the_step() { let (mut set, mut e) = typing("Z", &[Selection::cursor(0)]); type_chars(&mut set, &mut e, "abc"); @@ -270,7 +262,6 @@ fn switching_between_typing_and_deleting_ends_the_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn word_and_line_deletes_join_the_delete_of_their_direction() { let (mut set, mut e) = typing("let foo = bar;", &[Selection::cursor(13)]); e.delete_backward(&mut set).unwrap(); @@ -298,7 +289,6 @@ fn word_and_line_deletes_join_the_delete_of_their_direction() { } #[test] -#[ignore = "T-112: not implemented yet"] fn enter_starts_a_step_that_typing_after_it_joins() { let (mut set, mut e) = typing("\n", &[Selection::cursor(0)]); type_chars(&mut set, &mut e, "abc"); @@ -318,7 +308,6 @@ fn enter_starts_a_step_that_typing_after_it_joins() { } #[test] -#[ignore = "T-112: not implemented yet"] fn deleting_a_line_break_starts_a_step() { for line_break in ["\n", "\r\n", "\r"] { let start = format!("ab{line_break}cd"); @@ -351,7 +340,6 @@ fn deleting_a_line_break_starts_a_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn a_word_delete_across_a_line_break_starts_a_step() { let (mut set, mut e) = typing("ab\ncd", &[Selection::cursor(5)]); e.delete_backward(&mut set).unwrap(); @@ -363,7 +351,6 @@ fn a_word_delete_across_a_line_break_starts_a_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn a_pause_of_typing_pause_starts_a_step() { let (mut set, mut e) = typing("", &[Selection::cursor(0)]); e.set_time(Duration::ZERO); @@ -388,7 +375,6 @@ fn a_pause_of_typing_pause_starts_a_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn a_pause_splits_deletes_too() { let (mut set, mut e) = typing("abc", &[Selection::cursor(3)]); e.set_time(at(0)); @@ -399,7 +385,6 @@ fn a_pause_splits_deletes_too() { } #[test] -#[ignore = "T-112: not implemented yet"] fn without_a_time_or_with_time_going_back_nothing_splits() { let (mut set, mut e) = typing("", &[Selection::cursor(0)]); type_chars(&mut set, &mut e, "abc"); @@ -416,7 +401,6 @@ fn without_a_time_or_with_time_going_back_nothing_splits() { } #[test] -#[ignore = "T-112: not implemented yet"] fn under_explicit_grouping_time_changes_nothing() { let (mut set, mut e) = editor_with("", &[Selection::cursor(0)], UndoGrouping::Explicit); e.set_time(at(0)); @@ -436,7 +420,6 @@ fn under_explicit_grouping_time_changes_nothing() { } #[test] -#[ignore = "T-112: not implemented yet"] fn undo_and_redo_end_the_step() { let (mut set, mut e) = typing("", &[Selection::cursor(0)]); type_chars(&mut set, &mut e, "ab"); @@ -454,7 +437,6 @@ fn undo_and_redo_end_the_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn end_undo_group_ends_a_typing_step_and_makes_a_paste_one_step() { let (mut set, mut e) = typing("", &[Selection::cursor(0)]); type_chars(&mut set, &mut e, "ab"); @@ -469,7 +451,6 @@ fn end_undo_group_ends_a_typing_step_and_makes_a_paste_one_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn an_explicit_group_wins_over_the_typing_rules() { let (mut set, mut e) = typing("", &[Selection::cursor(0)]); type_chars(&mut set, &mut e, "a"); @@ -492,7 +473,6 @@ fn an_explicit_group_wins_over_the_typing_rules() { } #[test] -#[ignore = "T-112: not implemented yet"] fn changing_the_grouping_ends_any_group() { let (mut set, mut e) = typing("", &[Selection::cursor(0)]); type_chars(&mut set, &mut e, "a"); @@ -518,7 +498,6 @@ fn changing_the_grouping_ends_any_group() { } #[test] -#[ignore = "T-112: not implemented yet"] fn an_edit_with_nothing_to_do_keeps_the_step() { let (mut set, mut e) = typing("", &[Selection::cursor(0)]); type_chars(&mut set, &mut e, "ab"); @@ -536,7 +515,6 @@ fn an_edit_with_nothing_to_do_keeps_the_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn an_unknown_buffer_changes_nothing() { let (mut set, mut e) = typing("", &[Selection::cursor(0)]); let mut other = BufferSet::new(); @@ -556,7 +534,6 @@ fn an_unknown_buffer_changes_nothing() { } #[test] -#[ignore = "T-112: not implemented yet"] fn an_outside_transaction_splits_the_run() { let (mut set, mut e) = typing("", &[Selection::cursor(0)]); type_chars(&mut set, &mut e, "ab"); @@ -571,7 +548,6 @@ fn an_outside_transaction_splits_the_run() { } #[test] -#[ignore = "T-112: not implemented yet"] fn a_vim_command_under_typing_grouping_is_its_own_step() { let registry = CommandRegistry::with_vim_commands(); let (mut set, mut e) = typing("abc", &[Selection::cursor(0)]); @@ -591,7 +567,6 @@ fn a_vim_command_under_typing_grouping_is_its_own_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn a_clone_keeps_the_open_typing_step() { let (mut set, mut e) = typing("", &[Selection::cursor(0)]); e.set_time(at(100)); diff --git a/crates/helm-editor/tests/vscode_undo.rs b/crates/helm-editor/tests/vscode_undo.rs index 1c4381c..405b849 100644 --- a/crates/helm-editor/tests/vscode_undo.rs +++ b/crates/helm-editor/tests/vscode_undo.rs @@ -108,7 +108,6 @@ impl Window { } #[test] -#[ignore = "T-112: not implemented yet"] fn each_keymap_carries_its_grouping() { assert_eq!(vscode::keymap().undo_grouping(), UndoGrouping::Typing); assert_eq!(vim::keymap().undo_grouping(), UndoGrouping::Explicit); @@ -122,7 +121,6 @@ fn each_keymap_carries_its_grouping() { } #[test] -#[ignore = "T-112: not implemented yet"] fn dispatch_gives_the_editor_the_keymaps_grouping_on_a_run() { let mut keymap = Keymap::new("chords", vec![Mode::new("m", Typing::Insert)]) .unwrap() @@ -168,7 +166,6 @@ fn dispatch_gives_the_editor_the_keymaps_grouping_on_a_run() { } #[test] -#[ignore = "T-112: not implemented yet"] fn a_vscode_session_undoes_step_by_step() { let mut w = Window::new(vscode::keymap(), "", &[Selection::cursor(0)]); w.type_text("hello world"); @@ -205,7 +202,6 @@ fn a_vscode_session_undoes_step_by_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn backspace_and_word_and_line_deletes_undo_together() { let mut w = Window::new(vscode::keymap(), "let foo = bar;", &[Selection::cursor(13)]); w.keys("backspace alt-backspace cmd-backspace"); @@ -216,7 +212,6 @@ fn backspace_and_word_and_line_deletes_undo_together() { } #[test] -#[ignore = "T-112: not implemented yet"] fn typing_after_undo_starts_a_new_step() { let mut w = Window::new(vscode::keymap(), "", &[Selection::cursor(0)]); w.type_text("ab"); @@ -229,7 +224,6 @@ fn typing_after_undo_starts_a_new_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn typing_at_three_cursors_undoes_in_one_step() { let mut w = Window::new(vscode::keymap(), "let a = a + a;", &[Selection::cursor(4)]); w.keys("cmd-d shift-cmd-l"); @@ -248,7 +242,6 @@ fn typing_at_three_cursors_undoes_in_one_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn set_time_between_keys_splits_a_run_at_a_pause() { let mut w = Window::new(vscode::keymap(), "", &[Selection::cursor(0)]); let pause = Editor::TYPING_PAUSE; @@ -268,7 +261,6 @@ fn set_time_between_keys_splits_a_run_at_a_pause() { } #[test] -#[ignore = "T-112: not implemented yet"] fn switching_to_vim_ends_the_typing_step() { let mut w = Window::new(vscode::keymap(), "abc", &[Selection::cursor(0)]); w.type_text("xy"); @@ -285,7 +277,6 @@ fn switching_to_vim_ends_the_typing_step() { } #[test] -#[ignore = "T-112: not implemented yet"] fn switching_to_vscode_mid_insert_ends_the_vim_group_and_its_record() { let mut w = Window::new(vim::keymap(), "abc", &[Selection::cursor(0)]); w.type_text("ixy"); @@ -309,7 +300,6 @@ fn switching_to_vscode_mid_insert_ends_the_vim_group_and_its_record() { } #[test] -#[ignore = "T-112: not implemented yet"] fn with_helm_uis_close_on_each_switch_there_are_still_three_steps() { let mut w = Window::new(vim::keymap(), "abc", &[Selection::cursor(0)]); w.type_text("iy");