diff options
author | Mike Trinkala | 2023-02-09 14:28:33 +0000 |
---|---|---|
committer | GitHub | 2023-02-09 14:28:33 +0000 |
commit | 9d73a0d1128f8237eef2d4bf475496d4db081df2 (patch) | |
tree | 3b961c004955e5037bad40e2693bf727c83634d9 | |
parent | 7ebcf4e919a27b60610ba8f3a24a213282eb9ee6 (diff) |
Fix the infinite loop when copying the cursor to the top of the file (#5888)
Example:
```
test
testitem
```
Select line 2 with x, then type Alt-C; Helix will go into an infinite
loop. The saturating_sub keeps the head_row and anchor_row pinned at 0,
and a selection is never made since the first line is too short.
-rw-r--r-- | helix-term/src/commands.rs | 4 | ||||
-rw-r--r-- | helix-term/tests/test/commands.rs | 64 |
2 files changed, 68 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index e6cbed2c..d7d87b5a 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1617,6 +1617,10 @@ fn copy_selection_on_line(cx: &mut Context, direction: Direction) { sels += 1; } + if anchor_row == 0 && head_row == 0 { + break; + } + i += 1; } } diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 2ca9e395..e8d16bfa 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -132,6 +132,70 @@ async fn test_selection_duplication() -> anyhow::Result<()> { .as_str(), )) .await?; + + // Copy the selection to previous line, skipping the first line in the file + test(( + platform_line(indoc! {"\ + test + #[testitem|]# + "}) + .as_str(), + "<A-C>", + platform_line(indoc! {"\ + test + #[testitem|]# + "}) + .as_str(), + )) + .await?; + + // Copy the selection to previous line, including the first line in the file + test(( + platform_line(indoc! {"\ + test + #[test|]# + "}) + .as_str(), + "<A-C>", + platform_line(indoc! {"\ + #[test|]# + #(test|)# + "}) + .as_str(), + )) + .await?; + + // Copy the selection to next line, skipping the last line in the file + test(( + platform_line(indoc! {"\ + #[testitem|]# + test + "}) + .as_str(), + "C", + platform_line(indoc! {"\ + #[testitem|]# + test + "}) + .as_str(), + )) + .await?; + + // Copy the selection to next line, including the last line in the file + test(( + platform_line(indoc! {"\ + #[test|]# + test + "}) + .as_str(), + "C", + platform_line(indoc! {"\ + #(test|)# + #[test|]# + "}) + .as_str(), + )) + .await?; Ok(()) } |