on master help sign in
Fix next paragraph logic over muliple blank lines (#1951)

Fix #1928

commit6fc6f87260a2f11a892f09678fc6c10b01e88e3f authorIvan Tham <pickfire@riseup.net> dateTue 5 Apr 2022, 08:43 (5 years ago) parente7beb32
1 file changed+10−1
helix-core/src/movement.rs+10−1
helix-core/src/movement.rs+10−1
@@ -202,7 +202,8 @@ pub fn move_next_paragraph(
202202 let last_char =
203203 prev_grapheme_boundary(slice, slice.line_to_char(line + 1)) == range.cursor(slice);
204204 let curr_line_empty = rope_is_line_ending(slice.line(line));
205− let next_line_empty = rope_is_line_ending(slice.line(line.saturating_sub(1)));
205+ let next_line_empty =
206+ rope_is_line_ending(slice.line(slice.len_lines().saturating_sub(1).min(line + 1)));
206207 let curr_empty_to_line = curr_line_empty && !next_line_empty;
207208
208209 // skip character after paragraph boundary
@@ -1364,6 +1365,14 @@ mod test {
13641365 "here\n\nhave\n#[m|]#ultiple\nparagraph\n\n\n\n\n",
13651366 "here\n\nhave\n#[multiple\nparagraph\n\n\n\n\n|]#",
13661367 ),
1368+ (
1369+ "#[t|]#ext\n\n\nafter two blank lines\n\nmore text\n",
1370+ "#[text\n\n\n|]#after two blank lines\n\nmore text\n",
1371+ ),
1372+ (
1373+ "#[text\n\n\n|]#after two blank lines\n\nmore text\n",
1374+ "text\n\n\n#[after two blank lines\n\n|]#more text\n",
1375+ ),
13671376 ];
13681377
13691378 for (before, expected) in tests {