From 28fdccc0456f0079e2c1e224cde551bcbe6a0828 Mon Sep 17 00:00:00 2001 From: Gabriel Dinner-David Date: Sun, 25 Dec 2022 12:59:53 -0500 Subject: [PATCH 1/3] fix(commands): extend_line to proper line when count for both extend_line_(above/below) the check for if current line is selected now works if there is a count --- helix-term/src/commands.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 437e11b5c238..437048a12c6b 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2053,16 +2053,10 @@ fn extend_line_impl(cx: &mut Context, extend: Extend) { let selection = doc.selection(view.id).clone().transform(|range| { let (start_line, end_line) = range.line_range(text.slice(..)); - let start = text.line_to_char(match extend { - Extend::Above => start_line.saturating_sub(count - 1), - Extend::Below => start_line, - }); + let start = text.line_to_char(start_line); let end = text.line_to_char( - match extend { - Extend::Above => end_line + 1, // the start of next line - Extend::Below => end_line + count, - } - .min(text.len_lines()), + (end_line + 1) // newline of end_line + .min(text.len_lines()), ); // extend to previous/next line if current line is selected @@ -2076,8 +2070,11 @@ fn extend_line_impl(cx: &mut Context, extend: Extend) { } } else { match extend { - Extend::Above => (end, start), - Extend::Below => (start, end), + Extend::Above => (end, text.line_to_char(start_line.saturating_sub(count - 1))), + Extend::Below => ( + start, + text.line_to_char((end_line + count).min(text.len_lines())), + ), } }; From 6766e9a25c059dd9d88b882d721ead5101ad7c32 Mon Sep 17 00:00:00 2001 From: Gaby Dinner-David Date: Thu, 29 Dec 2022 15:26:42 -0700 Subject: [PATCH 2/3] add integration tests --- helix-term/tests/test/commands.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 95bd95b73a7e..b7434c801d33 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -311,3 +311,24 @@ async fn test_undo_redo() -> anyhow::Result<()> { Ok(()) } + +#[tokio::test(flavor = "multi_thread")] +async fn test_extend_line() -> anyhow::Result<()> { + // extend with line selected then count + test(( + platform_line("#[a|]#\na\na\n\n").as_str(), + "x2x", + platform_line("#[a\na\na\n|]#\n").as_str(), + )) + .await?; + + // extend with count on partial selection + test(( + platform_line("#[a|]#\na\n\n").as_str(), + "2x", + platform_line("#[a\na\n|]#\n").as_str(), + )) + .await?; + + Ok(()) +} From e5c3a7d1c20109567f3e4e88b804cf7239ae4215 Mon Sep 17 00:00:00 2001 From: Gabriel Dinner-David Date: Fri, 30 Dec 2022 10:42:37 -0500 Subject: [PATCH 3/3] extend line integration tests more readable --- helix-term/tests/test/commands.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index b7434c801d33..6e7275f5e411 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -316,17 +316,39 @@ async fn test_undo_redo() -> anyhow::Result<()> { async fn test_extend_line() -> anyhow::Result<()> { // extend with line selected then count test(( - platform_line("#[a|]#\na\na\n\n").as_str(), + platform_line(indoc! {"\ + #[l|]#orem + ipsum + dolor + + "}) + .as_str(), "x2x", - platform_line("#[a\na\na\n|]#\n").as_str(), + platform_line(indoc! {"\ + #[lorem + ipsum + dolor + |]# + "}) + .as_str(), )) .await?; // extend with count on partial selection test(( - platform_line("#[a|]#\na\n\n").as_str(), + platform_line(indoc! {"\ + #[l|]#orem + ipsum + + "}) + .as_str(), "2x", - platform_line("#[a\na\n|]#\n").as_str(), + platform_line(indoc! {"\ + #[lorem + ipsum + |]# + "}) + .as_str(), )) .await?;