Skip to content

Commit 68909dc

Browse files
authored
Fix append cursor location when selection anchor is at end of document (#4147)
1 parent c54a036 commit 68909dc

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

helix-term/src/commands.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -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]
90111
async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> {
91112
test_with_config(

0 commit comments

Comments
 (0)