editor: Fix cuts on end of line cutting whole line (#34553)
Closes #19816 Release Notes: - Improved `ctrl-k` (`editor::CutToEndOfLine`) behavior when used at the end of lines - Add option to make `editor::CutToEndOfLine` not gobble newlines. ```json { "context": "Editor", "bindings": { "ctrl-k": ["editor::CutToEndOfLine", { "stop_at_newlines": true }] } }, ``` --------- Co-authored-by: Peter Tripp <peter@zed.dev>
This commit is contained in:
@@ -6730,6 +6730,58 @@ async fn test_hard_wrap(cx: &mut TestAppContext) {
|
||||
));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_cut_line_ends(cx: &mut TestAppContext) {
|
||||
init_test(cx, |_| {});
|
||||
|
||||
let mut cx = EditorTestContext::new(cx).await;
|
||||
|
||||
cx.set_state(indoc! {"
|
||||
The quick« brownˇ»
|
||||
fox jumps overˇ
|
||||
the lazy dog"});
|
||||
cx.update_editor(|e, window, cx| e.cut(&Cut, window, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
The quickˇ
|
||||
ˇthe lazy dog"});
|
||||
|
||||
cx.set_state(indoc! {"
|
||||
The quick« brownˇ»
|
||||
fox jumps overˇ
|
||||
the lazy dog"});
|
||||
cx.update_editor(|e, window, cx| e.cut_to_end_of_line(&CutToEndOfLine::default(), window, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
The quickˇ
|
||||
fox jumps overˇthe lazy dog"});
|
||||
|
||||
cx.set_state(indoc! {"
|
||||
The quick« brownˇ»
|
||||
fox jumps overˇ
|
||||
the lazy dog"});
|
||||
cx.update_editor(|e, window, cx| {
|
||||
e.cut_to_end_of_line(
|
||||
&CutToEndOfLine {
|
||||
stop_at_newlines: true,
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
cx.assert_editor_state(indoc! {"
|
||||
The quickˇ
|
||||
fox jumps overˇ
|
||||
the lazy dog"});
|
||||
|
||||
cx.set_state(indoc! {"
|
||||
The quick« brownˇ»
|
||||
fox jumps overˇ
|
||||
the lazy dog"});
|
||||
cx.update_editor(|e, window, cx| e.kill_ring_cut(&KillRingCut, window, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
The quickˇ
|
||||
fox jumps overˇthe lazy dog"});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_clipboard(cx: &mut TestAppContext) {
|
||||
init_test(cx, |_| {});
|
||||
|
||||
Reference in New Issue
Block a user