actions.rs

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