1use gpui::AppContext;
2
3// actions!(
4// editor,
5// [
6// LineDown,
7// LineUp,
8// HalfPageDown,
9// HalfPageUp,
10// PageDown,
11// PageUp,
12// NextScreen,
13// ScrollCursorTop,
14// ScrollCursorCenter,
15// ScrollCursorBottom,
16// ]
17// );
18
19pub fn init(cx: &mut AppContext) {
20 // todo!()
21 // cx.add_action(Editor::next_screen);
22 // cx.add_action(Editor::scroll_cursor_top);
23 // cx.add_action(Editor::scroll_cursor_center);
24 // cx.add_action(Editor::scroll_cursor_bottom);
25 // cx.add_action(|this: &mut Editor, _: &LineDown, cx| {
26 // this.scroll_screen(&ScrollAmount::Line(1.), cx)
27 // });
28 // cx.add_action(|this: &mut Editor, _: &LineUp, cx| {
29 // this.scroll_screen(&ScrollAmount::Line(-1.), cx)
30 // });
31 // cx.add_action(|this: &mut Editor, _: &HalfPageDown, cx| {
32 // this.scroll_screen(&ScrollAmount::Page(0.5), cx)
33 // });
34 // cx.add_action(|this: &mut Editor, _: &HalfPageUp, cx| {
35 // this.scroll_screen(&ScrollAmount::Page(-0.5), cx)
36 // });
37 // cx.add_action(|this: &mut Editor, _: &PageDown, cx| {
38 // this.scroll_screen(&ScrollAmount::Page(1.), cx)
39 // });
40 // cx.add_action(|this: &mut Editor, _: &PageUp, cx| {
41 // this.scroll_screen(&ScrollAmount::Page(-1.), cx)
42 // });
43}
44
45// impl Editor {
46// pub fn next_screen(&mut self, _: &NextScreen, cx: &mut ViewContext<Editor>) -> Option<()> {
47// if self.take_rename(true, cx).is_some() {
48// return None;
49// }
50
51// if self.mouse_context_menu.read(cx).visible() {
52// return None;
53// }
54
55// if matches!(self.mode, EditorMode::SingleLine) {
56// cx.propagate_action();
57// return None;
58// }
59// self.request_autoscroll(Autoscroll::Next, cx);
60// Some(())
61// }
62
63// pub fn scroll(
64// &mut self,
65// scroll_position: Vector2F,
66// axis: Option<Axis>,
67// cx: &mut ViewContext<Self>,
68// ) {
69// self.scroll_manager.update_ongoing_scroll(axis);
70// self.set_scroll_position(scroll_position, cx);
71// }
72
73// fn scroll_cursor_top(editor: &mut Editor, _: &ScrollCursorTop, cx: &mut ViewContext<Editor>) {
74// let snapshot = editor.snapshot(cx).display_snapshot;
75// let scroll_margin_rows = editor.vertical_scroll_margin() as u32;
76
77// let mut new_screen_top = editor.selections.newest_display(cx).head();
78// *new_screen_top.row_mut() = new_screen_top.row().saturating_sub(scroll_margin_rows);
79// *new_screen_top.column_mut() = 0;
80// let new_screen_top = new_screen_top.to_offset(&snapshot, Bias::Left);
81// let new_anchor = snapshot.buffer_snapshot.anchor_before(new_screen_top);
82
83// editor.set_scroll_anchor(
84// ScrollAnchor {
85// anchor: new_anchor,
86// offset: Default::default(),
87// },
88// cx,
89// )
90// }
91
92// fn scroll_cursor_center(
93// editor: &mut Editor,
94// _: &ScrollCursorCenter,
95// cx: &mut ViewContext<Editor>,
96// ) {
97// let snapshot = editor.snapshot(cx).display_snapshot;
98// let visible_rows = if let Some(visible_rows) = editor.visible_line_count() {
99// visible_rows as u32
100// } else {
101// return;
102// };
103
104// let mut new_screen_top = editor.selections.newest_display(cx).head();
105// *new_screen_top.row_mut() = new_screen_top.row().saturating_sub(visible_rows / 2);
106// *new_screen_top.column_mut() = 0;
107// let new_screen_top = new_screen_top.to_offset(&snapshot, Bias::Left);
108// let new_anchor = snapshot.buffer_snapshot.anchor_before(new_screen_top);
109
110// editor.set_scroll_anchor(
111// ScrollAnchor {
112// anchor: new_anchor,
113// offset: Default::default(),
114// },
115// cx,
116// )
117// }
118
119// fn scroll_cursor_bottom(
120// editor: &mut Editor,
121// _: &ScrollCursorBottom,
122// cx: &mut ViewContext<Editor>,
123// ) {
124// let snapshot = editor.snapshot(cx).display_snapshot;
125// let scroll_margin_rows = editor.vertical_scroll_margin() as u32;
126// let visible_rows = if let Some(visible_rows) = editor.visible_line_count() {
127// visible_rows as u32
128// } else {
129// return;
130// };
131
132// let mut new_screen_top = editor.selections.newest_display(cx).head();
133// *new_screen_top.row_mut() = new_screen_top
134// .row()
135// .saturating_sub(visible_rows.saturating_sub(scroll_margin_rows));
136// *new_screen_top.column_mut() = 0;
137// let new_screen_top = new_screen_top.to_offset(&snapshot, Bias::Left);
138// let new_anchor = snapshot.buffer_snapshot.anchor_before(new_screen_top);
139
140// editor.set_scroll_anchor(
141// ScrollAnchor {
142// anchor: new_anchor,
143// offset: Default::default(),
144// },
145// cx,
146// )
147// }
148// }