on master help sign in
Fix append cursor location when selection anchor is at end of document (#4147)
68909dcGraic
helix-term/src/commands.rs+1−1
@@ -2222,7 +2222,7 @@ fn append_mode(cx: &mut Context) {
2222 .iter()
2222 .iter()
2223 .last()
2223 .last()
2224 .expect("selection should always have at least one range");
2224 .expect("selection should always have at least one range");
2225− if !last_range.is_empty() && last_range.head == end {
2225+ if !last_range.is_empty() && last_range.to() == end {
2226 let transaction = Transaction::change(
2226 let transaction = Transaction::change(
2227 doc.text(),
2227 doc.text(),
2228 [(end, end, Some(doc.line_ending.as_str().into()))].into_iter(),
2228 [(end, end, Some(doc.line_ending.as_str().into()))].into_iter(),
helix-term/tests/test/movement.rs+21
@@ -86,6 +86,27 @@ async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
86 Ok(())
86 Ok(())
87}
87}
88
88
89+#[tokio::test]
90+async fn cursor_position_append_eof() -> anyhow::Result<()> {
91+ // Selection is fowards
92+ test((
93+ "#[foo|]#",
94+ "abar<esc>",
95+ helpers::platform_line("#[foobar|]#\n").as_ref(),
96+ ))
97+ .await?;
98+
99+ // Selection is backwards
100+ test((
101+ "#[|foo]#",
102+ "abar<esc>",
103+ helpers::platform_line("#[foobar|]#\n").as_ref(),
104+ ))
105+ .await?;
106+
107+ Ok(())
108+}
109+
89#[tokio::test]
110#[tokio::test]
90async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> {
111async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> {
91 test_with_config(
112 test_with_config(