editor: Fix crash caused by editor::SelectPrevious
(#24660)
Closes #24345 Release Notes: - Fixed a crash caused by calling `editor::SelectPrevious` twice in a row. Co-authored-by: conrad <conrad@zed.dev>
This commit is contained in:
parent
7950368bc2
commit
bbea3a2184
2 changed files with 16 additions and 1 deletions
|
@ -5362,6 +5362,21 @@ async fn test_select_previous_with_single_caret(cx: &mut gpui::TestAppContext) {
|
||||||
cx.assert_editor_state("«abcˇ»\n«abcˇ» «abcˇ»\ndef«abcˇ»\n«abcˇ»");
|
cx.assert_editor_state("«abcˇ»\n«abcˇ» «abcˇ»\ndef«abcˇ»\n«abcˇ»");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_select_previous_empty_buffer(cx: &mut gpui::TestAppContext) {
|
||||||
|
init_test(cx, |_| {});
|
||||||
|
|
||||||
|
let mut cx = EditorTestContext::new(cx).await;
|
||||||
|
cx.set_state("aˇ");
|
||||||
|
|
||||||
|
cx.update_editor(|e, window, cx| e.select_previous(&SelectPrevious::default(), window, cx))
|
||||||
|
.unwrap();
|
||||||
|
cx.assert_editor_state("«aˇ»");
|
||||||
|
cx.update_editor(|e, window, cx| e.select_previous(&SelectPrevious::default(), window, cx))
|
||||||
|
.unwrap();
|
||||||
|
cx.assert_editor_state("«aˇ»");
|
||||||
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_select_previous_with_multiple_carets(cx: &mut gpui::TestAppContext) {
|
async fn test_select_previous_with_multiple_carets(cx: &mut gpui::TestAppContext) {
|
||||||
init_test(cx, |_| {});
|
init_test(cx, |_| {});
|
||||||
|
|
|
@ -7121,7 +7121,7 @@ impl<'a> Iterator for ReversedMultiBufferChunks<'a> {
|
||||||
self.offset -= 1;
|
self.offset -= 1;
|
||||||
Some("\n")
|
Some("\n")
|
||||||
} else {
|
} else {
|
||||||
let chunk = self.current_chunks.as_mut().unwrap().next().unwrap();
|
let chunk = self.current_chunks.as_mut().unwrap().next()?;
|
||||||
self.offset -= chunk.len();
|
self.offset -= chunk.len();
|
||||||
Some(chunk)
|
Some(chunk)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue