mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-16 15:11:25 +00:00
Fix scroll tests
For some reason in gpui2, the window contains an extra 59px of space..
This commit is contained in:
parent
2d59492aac
commit
3779316e4e
2 changed files with 157 additions and 122 deletions
|
@ -108,122 +108,140 @@ fn scroll_editor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg(test)]
|
#[cfg(test)]
|
||||||
// mod test {
|
mod test {
|
||||||
// use crate::{
|
use crate::{
|
||||||
// state::Mode,
|
state::Mode,
|
||||||
// test::{NeovimBackedTestContext, VimTestContext},
|
test::{NeovimBackedTestContext, VimTestContext},
|
||||||
// };
|
};
|
||||||
// use gpui::geometry::vector::vec2f;
|
use gpui::{point, px, size, Context};
|
||||||
// use indoc::indoc;
|
use indoc::indoc;
|
||||||
// use language::Point;
|
use language::Point;
|
||||||
|
|
||||||
// #[gpui::test]
|
#[gpui::test]
|
||||||
// async fn test_scroll(cx: &mut gpui::TestAppContext) {
|
async fn test_scroll(cx: &mut gpui::TestAppContext) {
|
||||||
// let mut cx = VimTestContext::new(cx, true).await;
|
let mut cx = VimTestContext::new(cx, true).await;
|
||||||
|
|
||||||
// let window = cx.window;
|
let (line_height, visible_line_count) = cx.editor(|editor, cx| {
|
||||||
// let line_height = cx.editor(|editor, cx| editor.style().text.line_height(cx.font_cache()));
|
(
|
||||||
// window.simulate_resize(vec2f(1000., 8.0 * line_height - 1.0), &mut cx);
|
editor
|
||||||
|
.style()
|
||||||
|
.unwrap()
|
||||||
|
.text
|
||||||
|
.line_height_in_pixels(cx.rem_size()),
|
||||||
|
editor.visible_line_count().unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
// cx.set_state(
|
let window = cx.window;
|
||||||
// indoc!(
|
let margin = cx
|
||||||
// "ˇone
|
.update_window(window, |_, cx| {
|
||||||
// two
|
cx.viewport_size().height - line_height * visible_line_count
|
||||||
// three
|
})
|
||||||
// four
|
.unwrap();
|
||||||
// five
|
cx.simulate_window_resize(
|
||||||
// six
|
cx.window,
|
||||||
// seven
|
size(px(1000.), margin + 8. * line_height - px(1.0)),
|
||||||
// eight
|
);
|
||||||
// nine
|
|
||||||
// ten
|
|
||||||
// eleven
|
|
||||||
// twelve
|
|
||||||
// "
|
|
||||||
// ),
|
|
||||||
// Mode::Normal,
|
|
||||||
// );
|
|
||||||
|
|
||||||
// cx.update_editor(|editor, cx| {
|
cx.set_state(
|
||||||
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 0.))
|
indoc!(
|
||||||
// });
|
"ˇone
|
||||||
// cx.simulate_keystrokes(["ctrl-e"]);
|
two
|
||||||
// cx.update_editor(|editor, cx| {
|
three
|
||||||
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 1.))
|
four
|
||||||
// });
|
five
|
||||||
// cx.simulate_keystrokes(["2", "ctrl-e"]);
|
six
|
||||||
// cx.update_editor(|editor, cx| {
|
seven
|
||||||
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 3.))
|
eight
|
||||||
// });
|
nine
|
||||||
// cx.simulate_keystrokes(["ctrl-y"]);
|
ten
|
||||||
// cx.update_editor(|editor, cx| {
|
eleven
|
||||||
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 2.))
|
twelve
|
||||||
// });
|
"
|
||||||
|
),
|
||||||
|
Mode::Normal,
|
||||||
|
);
|
||||||
|
|
||||||
// // does not select in normal mode
|
cx.update_editor(|editor, cx| {
|
||||||
// cx.simulate_keystrokes(["g", "g"]);
|
assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 0.))
|
||||||
// cx.update_editor(|editor, cx| {
|
});
|
||||||
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 0.))
|
cx.simulate_keystrokes(["ctrl-e"]);
|
||||||
// });
|
cx.update_editor(|editor, cx| {
|
||||||
// cx.simulate_keystrokes(["ctrl-d"]);
|
assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 1.))
|
||||||
// cx.update_editor(|editor, cx| {
|
});
|
||||||
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 3.0));
|
cx.simulate_keystrokes(["2", "ctrl-e"]);
|
||||||
// assert_eq!(
|
cx.update_editor(|editor, cx| {
|
||||||
// editor.selections.newest(cx).range(),
|
assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 3.))
|
||||||
// Point::new(6, 0)..Point::new(6, 0)
|
});
|
||||||
// )
|
cx.simulate_keystrokes(["ctrl-y"]);
|
||||||
// });
|
cx.update_editor(|editor, cx| {
|
||||||
|
assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 2.))
|
||||||
|
});
|
||||||
|
|
||||||
// // does select in visual mode
|
// does not select in normal mode
|
||||||
// cx.simulate_keystrokes(["g", "g"]);
|
cx.simulate_keystrokes(["g", "g"]);
|
||||||
// cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 0.))
|
assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 0.))
|
||||||
// });
|
});
|
||||||
// cx.simulate_keystrokes(["v", "ctrl-d"]);
|
cx.simulate_keystrokes(["ctrl-d"]);
|
||||||
// cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
// assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 3.0));
|
assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 3.0));
|
||||||
// assert_eq!(
|
assert_eq!(
|
||||||
// editor.selections.newest(cx).range(),
|
editor.selections.newest(cx).range(),
|
||||||
// Point::new(0, 0)..Point::new(6, 1)
|
Point::new(6, 0)..Point::new(6, 0)
|
||||||
// )
|
)
|
||||||
// });
|
});
|
||||||
// }
|
|
||||||
// #[gpui::test]
|
|
||||||
// async fn test_ctrl_d_u(cx: &mut gpui::TestAppContext) {
|
|
||||||
// let mut cx = NeovimBackedTestContext::new(cx).await;
|
|
||||||
|
|
||||||
// cx.set_scroll_height(10).await;
|
// does select in visual mode
|
||||||
|
cx.simulate_keystrokes(["g", "g"]);
|
||||||
|
cx.update_editor(|editor, cx| {
|
||||||
|
assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 0.))
|
||||||
|
});
|
||||||
|
cx.simulate_keystrokes(["v", "ctrl-d"]);
|
||||||
|
cx.update_editor(|editor, cx| {
|
||||||
|
assert_eq!(editor.snapshot(cx).scroll_position(), point(0., 3.0));
|
||||||
|
assert_eq!(
|
||||||
|
editor.selections.newest(cx).range(),
|
||||||
|
Point::new(0, 0)..Point::new(6, 1)
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_ctrl_d_u(cx: &mut gpui::TestAppContext) {
|
||||||
|
let mut cx = NeovimBackedTestContext::new(cx).await;
|
||||||
|
|
||||||
// pub fn sample_text(rows: usize, cols: usize, start_char: char) -> String {
|
cx.set_scroll_height(10).await;
|
||||||
// let mut text = String::new();
|
|
||||||
// for row in 0..rows {
|
|
||||||
// let c: char = (start_char as u32 + row as u32) as u8 as char;
|
|
||||||
// let mut line = c.to_string().repeat(cols);
|
|
||||||
// if row < rows - 1 {
|
|
||||||
// line.push('\n');
|
|
||||||
// }
|
|
||||||
// text += &line;
|
|
||||||
// }
|
|
||||||
// text
|
|
||||||
// }
|
|
||||||
// let content = "ˇ".to_owned() + &sample_text(26, 2, 'a');
|
|
||||||
// cx.set_shared_state(&content).await;
|
|
||||||
|
|
||||||
// // skip over the scrolloff at the top
|
pub fn sample_text(rows: usize, cols: usize, start_char: char) -> String {
|
||||||
// // test ctrl-d
|
let mut text = String::new();
|
||||||
// cx.simulate_shared_keystrokes(["4", "j", "ctrl-d"]).await;
|
for row in 0..rows {
|
||||||
// cx.assert_state_matches().await;
|
let c: char = (start_char as u32 + row as u32) as u8 as char;
|
||||||
// cx.simulate_shared_keystrokes(["ctrl-d"]).await;
|
let mut line = c.to_string().repeat(cols);
|
||||||
// cx.assert_state_matches().await;
|
if row < rows - 1 {
|
||||||
// cx.simulate_shared_keystrokes(["g", "g", "ctrl-d"]).await;
|
line.push('\n');
|
||||||
// cx.assert_state_matches().await;
|
}
|
||||||
|
text += &line;
|
||||||
|
}
|
||||||
|
text
|
||||||
|
}
|
||||||
|
let content = "ˇ".to_owned() + &sample_text(26, 2, 'a');
|
||||||
|
cx.set_shared_state(&content).await;
|
||||||
|
|
||||||
// // test ctrl-u
|
// skip over the scrolloff at the top
|
||||||
// cx.simulate_shared_keystrokes(["ctrl-u"]).await;
|
// test ctrl-d
|
||||||
// cx.assert_state_matches().await;
|
cx.simulate_shared_keystrokes(["4", "j", "ctrl-d"]).await;
|
||||||
// cx.simulate_shared_keystrokes(["ctrl-d", "ctrl-d", "4", "j", "ctrl-u", "ctrl-u"])
|
cx.assert_state_matches().await;
|
||||||
// .await;
|
cx.simulate_shared_keystrokes(["ctrl-d"]).await;
|
||||||
// cx.assert_state_matches().await;
|
cx.assert_state_matches().await;
|
||||||
// }
|
cx.simulate_shared_keystrokes(["g", "g", "ctrl-d"]).await;
|
||||||
// }
|
cx.assert_state_matches().await;
|
||||||
|
|
||||||
|
// test ctrl-u
|
||||||
|
cx.simulate_shared_keystrokes(["ctrl-u"]).await;
|
||||||
|
cx.assert_state_matches().await;
|
||||||
|
cx.simulate_shared_keystrokes(["ctrl-d", "ctrl-d", "4", "j", "ctrl-u", "ctrl-u"])
|
||||||
|
.await;
|
||||||
|
cx.assert_state_matches().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// todo!()
|
// todo!()
|
||||||
|
|
||||||
use editor::{scroll::VERTICAL_SCROLL_MARGIN, test::editor_test_context::ContextHandle};
|
use editor::{scroll::VERTICAL_SCROLL_MARGIN, test::editor_test_context::ContextHandle};
|
||||||
|
use gpui::{point, px, rems, size, Context};
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
use settings::SettingsStore;
|
use settings::SettingsStore;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -153,20 +154,36 @@ impl<'a> NeovimBackedTestContext<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo!()
|
pub async fn set_scroll_height(&mut self, rows: u32) {
|
||||||
// pub async fn set_scroll_height(&mut self, rows: u32) {
|
// match Zed's scrolling behavior
|
||||||
// // match Zed's scrolling behavior
|
self.neovim
|
||||||
// self.neovim
|
.set_option(&format!("scrolloff={}", VERTICAL_SCROLL_MARGIN))
|
||||||
// .set_option(&format!("scrolloff={}", VERTICAL_SCROLL_MARGIN))
|
.await;
|
||||||
// .await;
|
// +2 to account for the vim command UI at the bottom.
|
||||||
// // +2 to account for the vim command UI at the bottom.
|
self.neovim.set_option(&format!("lines={}", rows + 2)).await;
|
||||||
// self.neovim.set_option(&format!("lines={}", rows + 2)).await;
|
let (line_height, visible_line_count) = self.editor(|editor, cx| {
|
||||||
// let window = self.window;
|
(
|
||||||
// let line_height =
|
editor
|
||||||
// self.editor(|editor, cx| editor.style().text.line_height(cx.font_cache()));
|
.style()
|
||||||
|
.unwrap()
|
||||||
|
.text
|
||||||
|
.line_height_in_pixels(cx.rem_size()),
|
||||||
|
editor.visible_line_count().unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
// window.simulate_resize(vec2f(1000., (rows as f32) * line_height), &mut self.cx);
|
let window = self.window;
|
||||||
// }
|
let margin = self
|
||||||
|
.update_window(window, |_, cx| {
|
||||||
|
cx.viewport_size().height - line_height * visible_line_count
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
self.simulate_window_resize(
|
||||||
|
self.window,
|
||||||
|
size(px(1000.), margin + (rows as f32) * line_height),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn set_neovim_option(&mut self, option: &str) {
|
pub async fn set_neovim_option(&mut self, option: &str) {
|
||||||
self.neovim.set_option(option).await;
|
self.neovim.set_option(option).await;
|
||||||
|
|
Loading…
Reference in a new issue