Fix append cursor location when selection anchor is at end of document (#4147)
commit68909dcef46c7b68f1a92cdc7fd04eb89549b6fb
authorGraic <33105645+Graicc@users.noreply.github.com>
dateWed 12 Oct 2022, 09:34 (4 years ago)
parentc54a036
helix-term/src/commands.rs+1−1
@@ -2222,7 +2222,7 @@ fn append_mode(cx: &mut Context) {
22222222 .iter()
22232223 .last()
22242224 .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 {
22262226 let transaction = Transaction::change(
22272227 doc.text(),
22282228 [(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<()> {
8686 Ok(())
8787}
8888
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+
89110#[tokio::test]
90111async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> {
91112 test_with_config(