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

pull/4227/head
Graic 2 years ago committed by GitHub
parent c54a0363bb
commit 68909dcef4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2222,7 +2222,7 @@ fn append_mode(cx: &mut Context) {
.iter() .iter()
.last() .last()
.expect("selection should always have at least one range"); .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.to() == end {
let transaction = Transaction::change( let transaction = Transaction::change(
doc.text(), doc.text(),
[(end, end, Some(doc.line_ending.as_str().into()))].into_iter(), [(end, end, Some(doc.line_ending.as_str().into()))].into_iter(),

@ -86,6 +86,27 @@ async fn cursor_position_newly_opened_file() -> anyhow::Result<()> {
Ok(()) Ok(())
} }
#[tokio::test]
async fn cursor_position_append_eof() -> anyhow::Result<()> {
// Selection is fowards
test((
"#[foo|]#",
"abar<esc>",
helpers::platform_line("#[foobar|]#\n").as_ref(),
))
.await?;
// Selection is backwards
test((
"#[|foo]#",
"abar<esc>",
helpers::platform_line("#[foobar|]#\n").as_ref(),
))
.await?;
Ok(())
}
#[tokio::test] #[tokio::test]
async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> { async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> {
test_with_config( test_with_config(

Loading…
Cancel
Save