Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix append cursor location when selection anchor is at end of document #4147

Merged
merged 4 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,7 @@ fn append_mode(cx: &mut Context) {
.iter()
.last()
.expect("selection should always have at least one range");
if !last_range.is_empty() && last_range.head == end {
if !last_range.is_empty() && (last_range.head == end || last_range.anchor == end) {
the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved
let transaction = Transaction::change(
doc.text(),
[(end, end, Some(doc.line_ending.as_str().into()))].into_iter(),
Expand Down
19 changes: 19 additions & 0 deletions helix-term/tests/test/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
async fn cursor_position_append_eof() -> anyhow::Result<()> {
test((
"#[f|]#oo",
"eabar<esc>",
helpers::platform_line("#[foobar|]#\n").as_ref()
))
.await?;

test((
"foo#[|]#",
"babar<esc>",
helpers::platform_line("#[foobar|]#\n").as_ref()
))
.await?;
Graicc marked this conversation as resolved.
Show resolved Hide resolved

Ok(())
}

#[tokio::test]
async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> {
test_with_config(
Expand Down