Compare commits

...

1 Commits

Author SHA1 Message Date
Smit Barmase
c24a5dc56a make paste work 2025-05-22 00:42:04 +05:30
3 changed files with 48 additions and 9 deletions

View File

@@ -382,6 +382,27 @@ mod test {
fox jumps ˇover
the lazy doover
the lazy dog"});
// multiline, trailing newline
cx.set_shared_state(indoc! {"
The quick ˇbrown
fox jumps over"})
.await;
cx.simulate_shared_keystrokes("y a p").await;
cx.shared_clipboard().await.assert_eq("The quick brown\n\n");
cx.simulate_shared_keystrokes("j").await;
cx.shared_state().await.assert_eq(indoc! {"
The quick brown
ˇ
fox jumps over"});
cx.simulate_shared_keystrokes("p").await;
cx.shared_state().await.assert_eq(indoc! {"
The quick brown
ˇThe quick brown
fox jumps over"});
}
#[gpui::test]

View File

@@ -1400,7 +1400,7 @@ fn paragraph(
around: bool,
) -> Option<Range<DisplayPoint>> {
let mut paragraph_start = start_of_paragraph(map, relative_to);
let mut paragraph_end = end_of_paragraph(map, relative_to);
let mut paragraph_end = end_of_paragraph(map, relative_to, false);
let paragraph_end_row = paragraph_end.row();
let paragraph_ends_with_eof = paragraph_end_row == map.max_point().row();
@@ -1421,7 +1421,7 @@ fn paragraph(
}
} else {
let next_paragraph_start = DisplayPoint::new(paragraph_end_row + 1, 0);
paragraph_end = end_of_paragraph(map, next_paragraph_start);
paragraph_end = end_of_paragraph(map, next_paragraph_start, true);
}
}
@@ -1451,8 +1451,12 @@ pub fn start_of_paragraph(map: &DisplaySnapshot, display_point: DisplayPoint) ->
/// Returns a position of the end of the current paragraph, where a paragraph
/// is defined as a run of non-blank lines or a run of blank lines.
/// The trailing newline is excluded from the paragraph.
pub fn end_of_paragraph(map: &DisplaySnapshot, display_point: DisplayPoint) -> DisplayPoint {
/// If include_trailing_newline is true, the trailing newline is included in the paragraph.
pub fn end_of_paragraph(
map: &DisplaySnapshot,
display_point: DisplayPoint,
include_trailing_newline: bool,
) -> DisplayPoint {
let point = display_point.to_point(map);
if point.row == map.buffer_snapshot.max_row().0 {
return map.max_point();
@@ -1464,11 +1468,15 @@ pub fn end_of_paragraph(map: &DisplaySnapshot, display_point: DisplayPoint) -> D
let blank = map.buffer_snapshot.is_line_blank(MultiBufferRow(row));
if blank != is_current_line_blank {
let previous_row = row - 1;
return Point::new(
previous_row,
map.buffer_snapshot.line_len(MultiBufferRow(previous_row)),
)
.to_display_point(map);
if include_trailing_newline {
return Point::new(row, 0).to_display_point(map);
} else {
return Point::new(
previous_row,
map.buffer_snapshot.line_len(MultiBufferRow(previous_row)),
)
.to_display_point(map);
}
}
}

View File

@@ -32,3 +32,13 @@
{"Key":"u"}
{"Key":"shift-p"}
{"Get":{"state":"The quick brown\nfox jumps ˇover\nthe lazy doover\nthe lazy dog","mode":"Normal"}}
{"Put":{"state":"The quick ˇbrown\n\nfox jumps over"}}
{"Key":"y"}
{"Key":"a"}
{"Key":"p"}
{"Get":{"state":"ˇThe quick brown\n\nfox jumps over","mode":"Normal"}}
{"ReadRegister":{"name":"\"","value":"The quick brown\n\n"}}
{"Key":"j"}
{"Get":{"state":"The quick brown\nˇ\nfox jumps over","mode":"Normal"}}
{"Key":"p"}
{"Get":{"state":"The quick brown\n\nˇThe quick brown\n\nfox jumps over","mode":"Normal"}}