@@ -2,9 +2,9 @@
22mod integration {
33 use std::path::PathBuf;
44
5− use helix_core::{syntax::AutoPairConfig, Position, Selection, Tendril, Transaction};
5+ use helix_core::{syntax::AutoPairConfig, Position, Selection, Transaction};
66 use helix_term::{application::Application, args::Args, config::Config};
7− use helix_view::{current, doc, input::parse_macro};
7+ use helix_view::{doc, input::parse_macro};
88
99 use crossterm::event::{Event, KeyEvent};
1010 use indoc::indoc;
@@ -25,14 +25,14 @@ mod integration {
2525 let mut app =
2626 app.unwrap_or_else(|| Application::new(Args::default(), Config::default()).unwrap());
2727
28− let (view, doc) = current!(app.editor);
28+ let (view, doc) = helix_view::current!(app.editor);
29+ let sel = doc.selection(view.id).clone();
2930
31+ // replace the initial text with the input text
3032 doc.apply(
31− &Transaction::insert(
32− doc.text(),
33− &Selection::single(1, 0),
34− Tendril::from(&test_case.in_text),
35− )
33+ &Transaction::change_by_selection(&doc.text(), &sel, |_| {
34+ (0, doc.text().len_chars(), Some((&test_case.in_text).into()))
35+ })
3636 .with_selection(test_case.in_selection.clone()),
3737 view.id,
3838 );
@@ -80,12 +80,12 @@ mod integration {
8080 Args::default(),
8181 Config::default(),
8282 TestCase {
83− in_text: String::new(),
83+ in_text: "\n".into(),
8484 in_selection: Selection::single(0, 1),
8585 // TODO: fix incorrect selection on new doc
86− in_keys: String::from("ihello world<esc>hl"),
87− out_text: String::from("hello world\n"),
88− out_selection: Selection::single(11, 12),
86+ in_keys: "ihello world<esc>".into(),
87+ out_text: "hello world\n".into(),
88+ out_selection: Selection::single(12, 11),
8989 },
9090 )?;
9191
@@ -93,16 +93,74 @@ mod integration {
9393 }
9494
9595 #[tokio::test]
96− async fn auto_pairs_basic() -> anyhow::Result<()> {
96+ async fn insert_mode_cursor_position() -> anyhow::Result<()> {
9797 test_key_sequence_text_result(
9898 Args::default(),
9999 Config::default(),
100100 TestCase {
101101 in_text: String::new(),
102+ in_selection: Selection::single(0, 0),
103+ in_keys: "i".into(),
104+ out_text: String::new(),
105+ out_selection: Selection::single(0, 0),
106+ },
107+ )?;
108+
109+ test_key_sequence_text_result(
110+ Args::default(),
111+ Config::default(),
112+ TestCase {
113+ in_text: "\n".into(),
114+ in_selection: Selection::single(0, 1),
115+ in_keys: "i".into(),
116+ out_text: "\n".into(),
117+ out_selection: Selection::single(1, 0),
118+ },
119+ )?;
120+
121+ test_key_sequence_text_result(
122+ Args::default(),
123+ Config::default(),
124+ TestCase {
125+ in_text: "\n".into(),
102126 in_selection: Selection::single(0, 1),
103− in_keys: String::from("i(<esc>hl"),
104− out_text: String::from("()\n"),
105− out_selection: Selection::single(1, 2),
127+ in_keys: "i<esc>i".into(),
128+ out_text: "\n".into(),
129+ out_selection: Selection::single(1, 0),
130+ },
131+ )?;
132+
133+ Ok(())
134+ }
135+
136+ #[tokio::test]
137+ async fn insert_to_normal_mode_cursor_position() -> anyhow::Result<()> {
138+ test_key_sequence_text_result(
139+ Args::default(),
140+ Config::default(),
141+ TestCase {
142+ in_text: "\n".into(),
143+ in_selection: Selection::single(0, 1),
144+ in_keys: "i".into(),
145+ out_text: "\n".into(),
146+ out_selection: Selection::single(1, 0),
147+ },
148+ )?;
149+
150+ Ok(())
151+ }
152+
153+ #[tokio::test]
154+ async fn auto_pairs_basic() -> anyhow::Result<()> {
155+ test_key_sequence_text_result(
156+ Args::default(),
157+ Config::default(),
158+ TestCase {
159+ in_text: "\n".into(),
160+ in_selection: Selection::single(0, 1),
161+ in_keys: "i(<esc>".into(),
162+ out_text: "()\n".into(),
163+ out_selection: Selection::single(2, 1),
106164 },
107165 )?;
108166
@@ -116,11 +174,11 @@ mod integration {
116174 ..Default::default()
117175 },
118176 TestCase {
119− in_text: String::new(),
177+ in_text: "\n".into(),
120178 in_selection: Selection::single(0, 1),
121− in_keys: String::from("i(<esc>hl"),
122− out_text: String::from("(\n"),
123− out_selection: Selection::single(1, 2),
179+ in_keys: "i(<esc>".into(),
180+ out_text: "(\n".into(),
181+ out_selection: Selection::single(2, 1),
124182 },
125183 )?;
126184
@@ -136,15 +194,17 @@ mod integration {
136194 },
137195 Config::default(),
138196 TestCase {
139− in_text: String::from("void foo() {}"),
140− in_selection: Selection::single(12, 13),
141− in_keys: String::from("i<ret><esc>"),
142− out_text: String::from(indoc! {r#"
197+ in_text: "void foo() {}\n".into(),
198+ in_selection: Selection::single(13, 12),
199+ in_keys: "i<ret><esc>".into(),
200+ out_text: indoc! {r#"
143201 void foo() {
144202
145203 }
146− "#}),
147− out_selection: Selection::single(15, 16),
204+ "#}
205+ .trim_start()
206+ .into(),
207+ out_selection: Selection::single(16, 15),
148208 },
149209 )?;
150210