mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-13 05:42:59 +00:00
Implement select_all
for buffer
This commit is contained in:
parent
3d6336b12a
commit
324a6ff7ae
1 changed files with 26 additions and 0 deletions
|
@ -44,6 +44,7 @@ pub fn init(app: &mut MutableAppContext) {
|
|||
Binding::new("shift-down", "buffer:select_down", Some("BufferView")),
|
||||
Binding::new("shift-left", "buffer:select_left", Some("BufferView")),
|
||||
Binding::new("shift-right", "buffer:select_right", Some("BufferView")),
|
||||
Binding::new("cmd-a", "buffer:select_all", Some("BufferView")),
|
||||
Binding::new("pageup", "buffer:page_up", Some("BufferView")),
|
||||
Binding::new("pagedown", "buffer:page_down", Some("BufferView")),
|
||||
Binding::new("alt-cmd-[", "buffer:fold", Some("BufferView")),
|
||||
|
@ -73,6 +74,7 @@ pub fn init(app: &mut MutableAppContext) {
|
|||
app.add_action("buffer:select_down", BufferView::select_down);
|
||||
app.add_action("buffer:select_left", BufferView::select_left);
|
||||
app.add_action("buffer:select_right", BufferView::select_right);
|
||||
app.add_action("buffer:select_all", BufferView::select_all);
|
||||
app.add_action("buffer:page_up", BufferView::page_up);
|
||||
app.add_action("buffer:page_down", BufferView::page_down);
|
||||
app.add_action("buffer:fold", BufferView::fold);
|
||||
|
@ -816,6 +818,16 @@ impl BufferView {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn select_all(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
||||
let selection = Selection {
|
||||
start: Anchor::Start,
|
||||
end: Anchor::End,
|
||||
reversed: false,
|
||||
goal_column: None,
|
||||
};
|
||||
self.update_selections(vec![selection], false, ctx);
|
||||
}
|
||||
|
||||
pub fn selections_in_range<'a>(
|
||||
&'a self,
|
||||
range: Range<DisplayPoint>,
|
||||
|
@ -1844,6 +1856,20 @@ mod tests {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_select_all() {
|
||||
App::test((), |app| {
|
||||
let buffer = app.add_model(|ctx| Buffer::new(0, "abc\nde\nfgh", ctx));
|
||||
let settings = settings::channel(&app.font_cache()).unwrap().1;
|
||||
let (_, view) = app.add_window(|ctx| BufferView::for_buffer(buffer, settings, ctx));
|
||||
view.update(app, |b, ctx| b.select_all(&(), ctx));
|
||||
assert_eq!(
|
||||
view.read(app).selection_ranges(app.as_ref()),
|
||||
&[DisplayPoint::new(0, 0)..DisplayPoint::new(2, 3)]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
impl BufferView {
|
||||
fn selection_ranges(&self, app: &AppContext) -> Vec<Range<DisplayPoint>> {
|
||||
self.selections_in_range(DisplayPoint::zero()..self.max_point(app), app)
|
||||
|
|
Loading…
Reference in a new issue