Avoid holding borrow to editor while painting child elements
This commit is contained in:
parent
f2c63781f9
commit
3a8e9b5697
2 changed files with 648 additions and 670 deletions
|
@ -124,6 +124,180 @@ impl EditorElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn register_actions(&self, cx: &mut WindowContext) {
|
||||||
|
let view = &self.editor;
|
||||||
|
register_action(view, cx, Editor::move_left);
|
||||||
|
register_action(view, cx, Editor::move_right);
|
||||||
|
register_action(view, cx, Editor::move_down);
|
||||||
|
register_action(view, cx, Editor::move_up);
|
||||||
|
// on_action(cx, Editor::new_file); todo!()
|
||||||
|
// on_action(cx, Editor::new_file_in_direction); todo!()
|
||||||
|
register_action(view, cx, Editor::cancel);
|
||||||
|
register_action(view, cx, Editor::newline);
|
||||||
|
register_action(view, cx, Editor::newline_above);
|
||||||
|
register_action(view, cx, Editor::newline_below);
|
||||||
|
register_action(view, cx, Editor::backspace);
|
||||||
|
register_action(view, cx, Editor::delete);
|
||||||
|
register_action(view, cx, Editor::tab);
|
||||||
|
register_action(view, cx, Editor::tab_prev);
|
||||||
|
register_action(view, cx, Editor::indent);
|
||||||
|
register_action(view, cx, Editor::outdent);
|
||||||
|
register_action(view, cx, Editor::delete_line);
|
||||||
|
register_action(view, cx, Editor::join_lines);
|
||||||
|
register_action(view, cx, Editor::sort_lines_case_sensitive);
|
||||||
|
register_action(view, cx, Editor::sort_lines_case_insensitive);
|
||||||
|
register_action(view, cx, Editor::reverse_lines);
|
||||||
|
register_action(view, cx, Editor::shuffle_lines);
|
||||||
|
register_action(view, cx, Editor::convert_to_upper_case);
|
||||||
|
register_action(view, cx, Editor::convert_to_lower_case);
|
||||||
|
register_action(view, cx, Editor::convert_to_title_case);
|
||||||
|
register_action(view, cx, Editor::convert_to_snake_case);
|
||||||
|
register_action(view, cx, Editor::convert_to_kebab_case);
|
||||||
|
register_action(view, cx, Editor::convert_to_upper_camel_case);
|
||||||
|
register_action(view, cx, Editor::convert_to_lower_camel_case);
|
||||||
|
register_action(view, cx, Editor::delete_to_previous_word_start);
|
||||||
|
register_action(view, cx, Editor::delete_to_previous_subword_start);
|
||||||
|
register_action(view, cx, Editor::delete_to_next_word_end);
|
||||||
|
register_action(view, cx, Editor::delete_to_next_subword_end);
|
||||||
|
register_action(view, cx, Editor::delete_to_beginning_of_line);
|
||||||
|
register_action(view, cx, Editor::delete_to_end_of_line);
|
||||||
|
register_action(view, cx, Editor::cut_to_end_of_line);
|
||||||
|
register_action(view, cx, Editor::duplicate_line);
|
||||||
|
register_action(view, cx, Editor::move_line_up);
|
||||||
|
register_action(view, cx, Editor::move_line_down);
|
||||||
|
register_action(view, cx, Editor::transpose);
|
||||||
|
register_action(view, cx, Editor::cut);
|
||||||
|
register_action(view, cx, Editor::copy);
|
||||||
|
register_action(view, cx, Editor::paste);
|
||||||
|
register_action(view, cx, Editor::undo);
|
||||||
|
register_action(view, cx, Editor::redo);
|
||||||
|
register_action(view, cx, Editor::move_page_up);
|
||||||
|
register_action(view, cx, Editor::move_page_down);
|
||||||
|
register_action(view, cx, Editor::next_screen);
|
||||||
|
register_action(view, cx, Editor::scroll_cursor_top);
|
||||||
|
register_action(view, cx, Editor::scroll_cursor_center);
|
||||||
|
register_action(view, cx, Editor::scroll_cursor_bottom);
|
||||||
|
register_action(view, cx, |editor, _: &LineDown, cx| {
|
||||||
|
editor.scroll_screen(&ScrollAmount::Line(1.), cx)
|
||||||
|
});
|
||||||
|
register_action(view, cx, |editor, _: &LineUp, cx| {
|
||||||
|
editor.scroll_screen(&ScrollAmount::Line(-1.), cx)
|
||||||
|
});
|
||||||
|
register_action(view, cx, |editor, _: &HalfPageDown, cx| {
|
||||||
|
editor.scroll_screen(&ScrollAmount::Page(0.5), cx)
|
||||||
|
});
|
||||||
|
register_action(view, cx, |editor, _: &HalfPageUp, cx| {
|
||||||
|
editor.scroll_screen(&ScrollAmount::Page(-0.5), cx)
|
||||||
|
});
|
||||||
|
register_action(view, cx, |editor, _: &PageDown, cx| {
|
||||||
|
editor.scroll_screen(&ScrollAmount::Page(1.), cx)
|
||||||
|
});
|
||||||
|
register_action(view, cx, |editor, _: &PageUp, cx| {
|
||||||
|
editor.scroll_screen(&ScrollAmount::Page(-1.), cx)
|
||||||
|
});
|
||||||
|
register_action(view, cx, Editor::move_to_previous_word_start);
|
||||||
|
register_action(view, cx, Editor::move_to_previous_subword_start);
|
||||||
|
register_action(view, cx, Editor::move_to_next_word_end);
|
||||||
|
register_action(view, cx, Editor::move_to_next_subword_end);
|
||||||
|
register_action(view, cx, Editor::move_to_beginning_of_line);
|
||||||
|
register_action(view, cx, Editor::move_to_end_of_line);
|
||||||
|
register_action(view, cx, Editor::move_to_start_of_paragraph);
|
||||||
|
register_action(view, cx, Editor::move_to_end_of_paragraph);
|
||||||
|
register_action(view, cx, Editor::move_to_beginning);
|
||||||
|
register_action(view, cx, Editor::move_to_end);
|
||||||
|
register_action(view, cx, Editor::select_up);
|
||||||
|
register_action(view, cx, Editor::select_down);
|
||||||
|
register_action(view, cx, Editor::select_left);
|
||||||
|
register_action(view, cx, Editor::select_right);
|
||||||
|
register_action(view, cx, Editor::select_to_previous_word_start);
|
||||||
|
register_action(view, cx, Editor::select_to_previous_subword_start);
|
||||||
|
register_action(view, cx, Editor::select_to_next_word_end);
|
||||||
|
register_action(view, cx, Editor::select_to_next_subword_end);
|
||||||
|
register_action(view, cx, Editor::select_to_beginning_of_line);
|
||||||
|
register_action(view, cx, Editor::select_to_end_of_line);
|
||||||
|
register_action(view, cx, Editor::select_to_start_of_paragraph);
|
||||||
|
register_action(view, cx, Editor::select_to_end_of_paragraph);
|
||||||
|
register_action(view, cx, Editor::select_to_beginning);
|
||||||
|
register_action(view, cx, Editor::select_to_end);
|
||||||
|
register_action(view, cx, Editor::select_all);
|
||||||
|
register_action(view, cx, |editor, action, cx| {
|
||||||
|
editor.select_all_matches(action, cx).log_err();
|
||||||
|
});
|
||||||
|
register_action(view, cx, Editor::select_line);
|
||||||
|
register_action(view, cx, Editor::split_selection_into_lines);
|
||||||
|
register_action(view, cx, Editor::add_selection_above);
|
||||||
|
register_action(view, cx, Editor::add_selection_below);
|
||||||
|
register_action(view, cx, |editor, action, cx| {
|
||||||
|
editor.select_next(action, cx).log_err();
|
||||||
|
});
|
||||||
|
register_action(view, cx, |editor, action, cx| {
|
||||||
|
editor.select_previous(action, cx).log_err();
|
||||||
|
});
|
||||||
|
register_action(view, cx, Editor::toggle_comments);
|
||||||
|
register_action(view, cx, Editor::select_larger_syntax_node);
|
||||||
|
register_action(view, cx, Editor::select_smaller_syntax_node);
|
||||||
|
register_action(view, cx, Editor::move_to_enclosing_bracket);
|
||||||
|
register_action(view, cx, Editor::undo_selection);
|
||||||
|
register_action(view, cx, Editor::redo_selection);
|
||||||
|
register_action(view, cx, Editor::go_to_diagnostic);
|
||||||
|
register_action(view, cx, Editor::go_to_prev_diagnostic);
|
||||||
|
register_action(view, cx, Editor::go_to_hunk);
|
||||||
|
register_action(view, cx, Editor::go_to_prev_hunk);
|
||||||
|
register_action(view, cx, Editor::go_to_definition);
|
||||||
|
register_action(view, cx, Editor::go_to_definition_split);
|
||||||
|
register_action(view, cx, Editor::go_to_type_definition);
|
||||||
|
register_action(view, cx, Editor::go_to_type_definition_split);
|
||||||
|
register_action(view, cx, Editor::fold);
|
||||||
|
register_action(view, cx, Editor::fold_at);
|
||||||
|
register_action(view, cx, Editor::unfold_lines);
|
||||||
|
register_action(view, cx, Editor::unfold_at);
|
||||||
|
register_action(view, cx, Editor::fold_selected_ranges);
|
||||||
|
register_action(view, cx, Editor::show_completions);
|
||||||
|
register_action(view, cx, Editor::toggle_code_actions);
|
||||||
|
// on_action(cx, Editor::open_excerpts); todo!()
|
||||||
|
register_action(view, cx, Editor::toggle_soft_wrap);
|
||||||
|
register_action(view, cx, Editor::toggle_inlay_hints);
|
||||||
|
register_action(view, cx, Editor::reveal_in_finder);
|
||||||
|
register_action(view, cx, Editor::copy_path);
|
||||||
|
register_action(view, cx, Editor::copy_relative_path);
|
||||||
|
register_action(view, cx, Editor::copy_highlight_json);
|
||||||
|
register_action(view, cx, |editor, action, cx| {
|
||||||
|
editor
|
||||||
|
.format(action, cx)
|
||||||
|
.map(|task| task.detach_and_log_err(cx));
|
||||||
|
});
|
||||||
|
register_action(view, cx, Editor::restart_language_server);
|
||||||
|
register_action(view, cx, Editor::show_character_palette);
|
||||||
|
// on_action(cx, Editor::confirm_completion); todo!()
|
||||||
|
register_action(view, cx, |editor, action, cx| {
|
||||||
|
editor
|
||||||
|
.confirm_code_action(action, cx)
|
||||||
|
.map(|task| task.detach_and_log_err(cx));
|
||||||
|
});
|
||||||
|
register_action(view, cx, |editor, action, cx| {
|
||||||
|
editor
|
||||||
|
.rename(action, cx)
|
||||||
|
.map(|task| task.detach_and_log_err(cx));
|
||||||
|
});
|
||||||
|
register_action(view, cx, |editor, action, cx| {
|
||||||
|
editor
|
||||||
|
.confirm_rename(action, cx)
|
||||||
|
.map(|task| task.detach_and_log_err(cx));
|
||||||
|
});
|
||||||
|
register_action(view, cx, |editor, action, cx| {
|
||||||
|
editor
|
||||||
|
.find_all_references(action, cx)
|
||||||
|
.map(|task| task.detach_and_log_err(cx));
|
||||||
|
});
|
||||||
|
register_action(view, cx, Editor::next_copilot_suggestion);
|
||||||
|
register_action(view, cx, Editor::previous_copilot_suggestion);
|
||||||
|
register_action(view, cx, Editor::copilot_suggest);
|
||||||
|
register_action(view, cx, Editor::context_menu_first);
|
||||||
|
register_action(view, cx, Editor::context_menu_prev);
|
||||||
|
register_action(view, cx, Editor::context_menu_next);
|
||||||
|
register_action(view, cx, Editor::context_menu_last);
|
||||||
|
}
|
||||||
|
|
||||||
fn mouse_down(
|
fn mouse_down(
|
||||||
editor: &mut Editor,
|
editor: &mut Editor,
|
||||||
event: &MouseDownEvent,
|
event: &MouseDownEvent,
|
||||||
|
@ -459,7 +633,6 @@ impl EditorElement {
|
||||||
&mut self,
|
&mut self,
|
||||||
bounds: Bounds<Pixels>,
|
bounds: Bounds<Pixels>,
|
||||||
layout: &mut LayoutState,
|
layout: &mut LayoutState,
|
||||||
editor: &mut Editor,
|
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
) {
|
) {
|
||||||
let line_height = layout.position_map.line_height;
|
let line_height = layout.position_map.line_height;
|
||||||
|
@ -616,14 +789,19 @@ impl EditorElement {
|
||||||
&mut self,
|
&mut self,
|
||||||
text_bounds: Bounds<Pixels>,
|
text_bounds: Bounds<Pixels>,
|
||||||
layout: &mut LayoutState,
|
layout: &mut LayoutState,
|
||||||
editor: &mut Editor,
|
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
) {
|
) {
|
||||||
let scroll_position = layout.position_map.snapshot.scroll_position();
|
let scroll_position = layout.position_map.snapshot.scroll_position();
|
||||||
let start_row = layout.visible_display_row_range.start;
|
let start_row = layout.visible_display_row_range.start;
|
||||||
let content_origin = text_bounds.origin + point(layout.gutter_margin, Pixels::ZERO);
|
let content_origin = text_bounds.origin + point(layout.gutter_margin, Pixels::ZERO);
|
||||||
let line_end_overshoot = 0.15 * layout.position_map.line_height;
|
let line_end_overshoot = 0.15 * layout.position_map.line_height;
|
||||||
let whitespace_setting = editor.buffer.read(cx).settings_at(0, cx).show_whitespaces;
|
let whitespace_setting = self
|
||||||
|
.editor
|
||||||
|
.read(cx)
|
||||||
|
.buffer
|
||||||
|
.read(cx)
|
||||||
|
.settings_at(0, cx)
|
||||||
|
.show_whitespaces;
|
||||||
|
|
||||||
cx.with_content_mask(
|
cx.with_content_mask(
|
||||||
Some(ContentMask {
|
Some(ContentMask {
|
||||||
|
@ -748,7 +926,7 @@ impl EditorElement {
|
||||||
invisible_display_ranges.push(selection.range.clone());
|
invisible_display_ranges.push(selection.range.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if !selection.is_local || editor.show_local_cursors(cx) {
|
if !selection.is_local || self.editor.read(cx).show_local_cursors(cx) {
|
||||||
let cursor_position = selection.head;
|
let cursor_position = selection.head;
|
||||||
if layout
|
if layout
|
||||||
.visible_display_row_range
|
.visible_display_row_range
|
||||||
|
@ -800,12 +978,14 @@ impl EditorElement {
|
||||||
* layout.position_map.line_height
|
* layout.position_map.line_height
|
||||||
- layout.position_map.scroll_position.y;
|
- layout.position_map.scroll_position.y;
|
||||||
if selection.is_newest {
|
if selection.is_newest {
|
||||||
|
self.editor.update(cx, |editor, _| {
|
||||||
editor.pixel_position_of_newest_cursor = Some(point(
|
editor.pixel_position_of_newest_cursor = Some(point(
|
||||||
text_bounds.origin.x + x + block_width / 2.,
|
text_bounds.origin.x + x + block_width / 2.,
|
||||||
text_bounds.origin.y
|
text_bounds.origin.y
|
||||||
+ y
|
+ y
|
||||||
+ layout.position_map.line_height / 2.,
|
+ layout.position_map.line_height / 2.,
|
||||||
));
|
))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
cursors.push(Cursor {
|
cursors.push(Cursor {
|
||||||
color: selection_style.cursor,
|
color: selection_style.cursor,
|
||||||
|
@ -1217,7 +1397,6 @@ impl EditorElement {
|
||||||
&mut self,
|
&mut self,
|
||||||
bounds: Bounds<Pixels>,
|
bounds: Bounds<Pixels>,
|
||||||
layout: &mut LayoutState,
|
layout: &mut LayoutState,
|
||||||
editor: &mut Editor,
|
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
) {
|
) {
|
||||||
let scroll_position = layout.position_map.snapshot.scroll_position();
|
let scroll_position = layout.position_map.snapshot.scroll_position();
|
||||||
|
@ -1237,7 +1416,7 @@ impl EditorElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn column_pixels(&self, column: usize, cx: &ViewContext<Editor>) -> Pixels {
|
fn column_pixels(&self, column: usize, cx: &WindowContext) -> Pixels {
|
||||||
let style = &self.style;
|
let style = &self.style;
|
||||||
let font_size = style.text.font_size.to_pixels(cx.rem_size());
|
let font_size = style.text.font_size.to_pixels(cx.rem_size());
|
||||||
let layout = cx
|
let layout = cx
|
||||||
|
@ -1258,7 +1437,7 @@ impl EditorElement {
|
||||||
layout.width
|
layout.width
|
||||||
}
|
}
|
||||||
|
|
||||||
fn max_line_number_width(&self, snapshot: &EditorSnapshot, cx: &ViewContext<Editor>) -> Pixels {
|
fn max_line_number_width(&self, snapshot: &EditorSnapshot, cx: &WindowContext) -> Pixels {
|
||||||
let digit_count = (snapshot.max_buffer_row() as f32 + 1.).log10().floor() as usize + 1;
|
let digit_count = (snapshot.max_buffer_row() as f32 + 1.).log10().floor() as usize + 1;
|
||||||
self.column_pixels(digit_count, cx)
|
self.column_pixels(digit_count, cx)
|
||||||
}
|
}
|
||||||
|
@ -1413,7 +1592,7 @@ impl EditorElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layout_lines(
|
fn layout_lines(
|
||||||
&mut self,
|
&self,
|
||||||
rows: Range<u32>,
|
rows: Range<u32>,
|
||||||
line_number_layouts: &[Option<ShapedLine>],
|
line_number_layouts: &[Option<ShapedLine>],
|
||||||
snapshot: &EditorSnapshot,
|
snapshot: &EditorSnapshot,
|
||||||
|
@ -1469,10 +1648,10 @@ impl EditorElement {
|
||||||
|
|
||||||
fn compute_layout(
|
fn compute_layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
editor: &mut Editor,
|
|
||||||
cx: &mut ViewContext<'_, Editor>,
|
|
||||||
mut bounds: Bounds<Pixels>,
|
mut bounds: Bounds<Pixels>,
|
||||||
|
cx: &mut WindowContext,
|
||||||
) -> LayoutState {
|
) -> LayoutState {
|
||||||
|
self.editor.update(cx, |editor, cx| {
|
||||||
// let mut size = constraint.max;
|
// let mut size = constraint.max;
|
||||||
// if size.x.is_infinite() {
|
// if size.x.is_infinite() {
|
||||||
// unimplemented!("we don't yet handle an infinite width constraint on buffer elements");
|
// unimplemented!("we don't yet handle an infinite width constraint on buffer elements");
|
||||||
|
@ -1835,21 +2014,6 @@ impl EditorElement {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
// todo!("context_menu")
|
|
||||||
// if let Some((_, context_menu)) = context_menu.as_mut() {
|
|
||||||
// context_menu.layout(
|
|
||||||
// SizeConstraint {
|
|
||||||
// min: gpui::Point::<Pixels>::zero(),
|
|
||||||
// max: point(
|
|
||||||
// cx.window_size().x * 0.7,
|
|
||||||
// (12. * line_height).min((size.y - line_height) / 2.),
|
|
||||||
// ),
|
|
||||||
// },
|
|
||||||
// editor,
|
|
||||||
// cx,
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// todo!("hover popovers")
|
// todo!("hover popovers")
|
||||||
// if let Some((_, hover_popovers)) = hover.as_mut() {
|
// if let Some((_, hover_popovers)) = hover.as_mut() {
|
||||||
// for hover_popover in hover_popovers.iter_mut() {
|
// for hover_popover in hover_popovers.iter_mut() {
|
||||||
|
@ -1941,11 +2105,12 @@ impl EditorElement {
|
||||||
space_invisible,
|
space_invisible,
|
||||||
// hover_popovers: hover,
|
// hover_popovers: hover,
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn layout_blocks(
|
fn layout_blocks(
|
||||||
&mut self,
|
&self,
|
||||||
rows: Range<u32>,
|
rows: Range<u32>,
|
||||||
snapshot: &EditorSnapshot,
|
snapshot: &EditorSnapshot,
|
||||||
editor_width: Pixels,
|
editor_width: Pixels,
|
||||||
|
@ -2446,8 +2611,8 @@ impl Element for EditorElement {
|
||||||
cx: &mut gpui::WindowContext,
|
cx: &mut gpui::WindowContext,
|
||||||
) {
|
) {
|
||||||
let editor = self.editor.clone();
|
let editor = self.editor.clone();
|
||||||
editor.update(cx, |editor, cx| {
|
|
||||||
let mut layout = self.compute_layout(editor, cx, bounds);
|
let mut layout = self.compute_layout(bounds, cx);
|
||||||
let gutter_bounds = Bounds {
|
let gutter_bounds = Bounds {
|
||||||
origin: bounds.origin,
|
origin: bounds.origin,
|
||||||
size: layout.gutter_size,
|
size: layout.gutter_size,
|
||||||
|
@ -2457,44 +2622,33 @@ impl Element for EditorElement {
|
||||||
size: layout.text_size,
|
size: layout.text_size,
|
||||||
};
|
};
|
||||||
|
|
||||||
let dispatch_context = editor.dispatch_context(cx);
|
let focus_handle = editor.focus_handle(cx);
|
||||||
let editor_handle = cx.view().clone();
|
let dispatch_context = self.editor.read(cx).dispatch_context(cx);
|
||||||
cx.with_key_dispatch(
|
cx.with_key_dispatch(dispatch_context, Some(focus_handle.clone()), |_, cx| {
|
||||||
dispatch_context,
|
self.register_actions(cx);
|
||||||
Some(editor.focus_handle.clone()),
|
|
||||||
|_, cx| {
|
|
||||||
register_actions(&editor_handle, cx);
|
|
||||||
|
|
||||||
// We call with_z_index to establish a new stacking context.
|
// We call with_z_index to establish a new stacking context.
|
||||||
cx.with_z_index(0, |cx| {
|
cx.with_z_index(0, |cx| {
|
||||||
cx.with_content_mask(Some(ContentMask { bounds }), |cx| {
|
cx.with_content_mask(Some(ContentMask { bounds }), |cx| {
|
||||||
// Paint mouse listeners first, so any elements we paint on top of the editor
|
// Paint mouse listeners first, so any elements we paint on top of the editor
|
||||||
// take precedence.
|
// take precedence.
|
||||||
self.paint_mouse_listeners(
|
self.paint_mouse_listeners(bounds, gutter_bounds, text_bounds, &layout, cx);
|
||||||
bounds,
|
let input_handler = ElementInputHandler::new(bounds, self.editor.clone(), cx);
|
||||||
gutter_bounds,
|
cx.handle_input(&focus_handle, input_handler);
|
||||||
text_bounds,
|
|
||||||
&layout,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
let input_handler = ElementInputHandler::new(bounds, editor_handle, cx);
|
|
||||||
cx.handle_input(&editor.focus_handle, input_handler);
|
|
||||||
|
|
||||||
self.paint_background(gutter_bounds, text_bounds, &layout, cx);
|
self.paint_background(gutter_bounds, text_bounds, &layout, cx);
|
||||||
if layout.gutter_size.width > Pixels::ZERO {
|
if layout.gutter_size.width > Pixels::ZERO {
|
||||||
self.paint_gutter(gutter_bounds, &mut layout, editor, cx);
|
self.paint_gutter(gutter_bounds, &mut layout, cx);
|
||||||
}
|
}
|
||||||
self.paint_text(text_bounds, &mut layout, editor, cx);
|
self.paint_text(text_bounds, &mut layout, cx);
|
||||||
|
|
||||||
if !layout.blocks.is_empty() {
|
if !layout.blocks.is_empty() {
|
||||||
cx.with_element_id(Some("editor_blocks"), |cx| {
|
cx.with_element_id(Some("editor_blocks"), |cx| {
|
||||||
self.paint_blocks(bounds, &mut layout, editor, cx);
|
self.paint_blocks(bounds, &mut layout, cx);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3932,179 +4086,6 @@ fn scale_horizontal_mouse_autoscroll_delta(delta: Pixels) -> f32 {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
fn register_actions(view: &View<Editor>, cx: &mut WindowContext) {
|
|
||||||
register_action(view, cx, Editor::move_left);
|
|
||||||
register_action(view, cx, Editor::move_right);
|
|
||||||
register_action(view, cx, Editor::move_down);
|
|
||||||
register_action(view, cx, Editor::move_up);
|
|
||||||
// on_action(cx, Editor::new_file); todo!()
|
|
||||||
// on_action(cx, Editor::new_file_in_direction); todo!()
|
|
||||||
register_action(view, cx, Editor::cancel);
|
|
||||||
register_action(view, cx, Editor::newline);
|
|
||||||
register_action(view, cx, Editor::newline_above);
|
|
||||||
register_action(view, cx, Editor::newline_below);
|
|
||||||
register_action(view, cx, Editor::backspace);
|
|
||||||
register_action(view, cx, Editor::delete);
|
|
||||||
register_action(view, cx, Editor::tab);
|
|
||||||
register_action(view, cx, Editor::tab_prev);
|
|
||||||
register_action(view, cx, Editor::indent);
|
|
||||||
register_action(view, cx, Editor::outdent);
|
|
||||||
register_action(view, cx, Editor::delete_line);
|
|
||||||
register_action(view, cx, Editor::join_lines);
|
|
||||||
register_action(view, cx, Editor::sort_lines_case_sensitive);
|
|
||||||
register_action(view, cx, Editor::sort_lines_case_insensitive);
|
|
||||||
register_action(view, cx, Editor::reverse_lines);
|
|
||||||
register_action(view, cx, Editor::shuffle_lines);
|
|
||||||
register_action(view, cx, Editor::convert_to_upper_case);
|
|
||||||
register_action(view, cx, Editor::convert_to_lower_case);
|
|
||||||
register_action(view, cx, Editor::convert_to_title_case);
|
|
||||||
register_action(view, cx, Editor::convert_to_snake_case);
|
|
||||||
register_action(view, cx, Editor::convert_to_kebab_case);
|
|
||||||
register_action(view, cx, Editor::convert_to_upper_camel_case);
|
|
||||||
register_action(view, cx, Editor::convert_to_lower_camel_case);
|
|
||||||
register_action(view, cx, Editor::delete_to_previous_word_start);
|
|
||||||
register_action(view, cx, Editor::delete_to_previous_subword_start);
|
|
||||||
register_action(view, cx, Editor::delete_to_next_word_end);
|
|
||||||
register_action(view, cx, Editor::delete_to_next_subword_end);
|
|
||||||
register_action(view, cx, Editor::delete_to_beginning_of_line);
|
|
||||||
register_action(view, cx, Editor::delete_to_end_of_line);
|
|
||||||
register_action(view, cx, Editor::cut_to_end_of_line);
|
|
||||||
register_action(view, cx, Editor::duplicate_line);
|
|
||||||
register_action(view, cx, Editor::move_line_up);
|
|
||||||
register_action(view, cx, Editor::move_line_down);
|
|
||||||
register_action(view, cx, Editor::transpose);
|
|
||||||
register_action(view, cx, Editor::cut);
|
|
||||||
register_action(view, cx, Editor::copy);
|
|
||||||
register_action(view, cx, Editor::paste);
|
|
||||||
register_action(view, cx, Editor::undo);
|
|
||||||
register_action(view, cx, Editor::redo);
|
|
||||||
register_action(view, cx, Editor::move_page_up);
|
|
||||||
register_action(view, cx, Editor::move_page_down);
|
|
||||||
register_action(view, cx, Editor::next_screen);
|
|
||||||
register_action(view, cx, Editor::scroll_cursor_top);
|
|
||||||
register_action(view, cx, Editor::scroll_cursor_center);
|
|
||||||
register_action(view, cx, Editor::scroll_cursor_bottom);
|
|
||||||
register_action(view, cx, |editor, _: &LineDown, cx| {
|
|
||||||
editor.scroll_screen(&ScrollAmount::Line(1.), cx)
|
|
||||||
});
|
|
||||||
register_action(view, cx, |editor, _: &LineUp, cx| {
|
|
||||||
editor.scroll_screen(&ScrollAmount::Line(-1.), cx)
|
|
||||||
});
|
|
||||||
register_action(view, cx, |editor, _: &HalfPageDown, cx| {
|
|
||||||
editor.scroll_screen(&ScrollAmount::Page(0.5), cx)
|
|
||||||
});
|
|
||||||
register_action(view, cx, |editor, _: &HalfPageUp, cx| {
|
|
||||||
editor.scroll_screen(&ScrollAmount::Page(-0.5), cx)
|
|
||||||
});
|
|
||||||
register_action(view, cx, |editor, _: &PageDown, cx| {
|
|
||||||
editor.scroll_screen(&ScrollAmount::Page(1.), cx)
|
|
||||||
});
|
|
||||||
register_action(view, cx, |editor, _: &PageUp, cx| {
|
|
||||||
editor.scroll_screen(&ScrollAmount::Page(-1.), cx)
|
|
||||||
});
|
|
||||||
register_action(view, cx, Editor::move_to_previous_word_start);
|
|
||||||
register_action(view, cx, Editor::move_to_previous_subword_start);
|
|
||||||
register_action(view, cx, Editor::move_to_next_word_end);
|
|
||||||
register_action(view, cx, Editor::move_to_next_subword_end);
|
|
||||||
register_action(view, cx, Editor::move_to_beginning_of_line);
|
|
||||||
register_action(view, cx, Editor::move_to_end_of_line);
|
|
||||||
register_action(view, cx, Editor::move_to_start_of_paragraph);
|
|
||||||
register_action(view, cx, Editor::move_to_end_of_paragraph);
|
|
||||||
register_action(view, cx, Editor::move_to_beginning);
|
|
||||||
register_action(view, cx, Editor::move_to_end);
|
|
||||||
register_action(view, cx, Editor::select_up);
|
|
||||||
register_action(view, cx, Editor::select_down);
|
|
||||||
register_action(view, cx, Editor::select_left);
|
|
||||||
register_action(view, cx, Editor::select_right);
|
|
||||||
register_action(view, cx, Editor::select_to_previous_word_start);
|
|
||||||
register_action(view, cx, Editor::select_to_previous_subword_start);
|
|
||||||
register_action(view, cx, Editor::select_to_next_word_end);
|
|
||||||
register_action(view, cx, Editor::select_to_next_subword_end);
|
|
||||||
register_action(view, cx, Editor::select_to_beginning_of_line);
|
|
||||||
register_action(view, cx, Editor::select_to_end_of_line);
|
|
||||||
register_action(view, cx, Editor::select_to_start_of_paragraph);
|
|
||||||
register_action(view, cx, Editor::select_to_end_of_paragraph);
|
|
||||||
register_action(view, cx, Editor::select_to_beginning);
|
|
||||||
register_action(view, cx, Editor::select_to_end);
|
|
||||||
register_action(view, cx, Editor::select_all);
|
|
||||||
register_action(view, cx, |editor, action, cx| {
|
|
||||||
editor.select_all_matches(action, cx).log_err();
|
|
||||||
});
|
|
||||||
register_action(view, cx, Editor::select_line);
|
|
||||||
register_action(view, cx, Editor::split_selection_into_lines);
|
|
||||||
register_action(view, cx, Editor::add_selection_above);
|
|
||||||
register_action(view, cx, Editor::add_selection_below);
|
|
||||||
register_action(view, cx, |editor, action, cx| {
|
|
||||||
editor.select_next(action, cx).log_err();
|
|
||||||
});
|
|
||||||
register_action(view, cx, |editor, action, cx| {
|
|
||||||
editor.select_previous(action, cx).log_err();
|
|
||||||
});
|
|
||||||
register_action(view, cx, Editor::toggle_comments);
|
|
||||||
register_action(view, cx, Editor::select_larger_syntax_node);
|
|
||||||
register_action(view, cx, Editor::select_smaller_syntax_node);
|
|
||||||
register_action(view, cx, Editor::move_to_enclosing_bracket);
|
|
||||||
register_action(view, cx, Editor::undo_selection);
|
|
||||||
register_action(view, cx, Editor::redo_selection);
|
|
||||||
register_action(view, cx, Editor::go_to_diagnostic);
|
|
||||||
register_action(view, cx, Editor::go_to_prev_diagnostic);
|
|
||||||
register_action(view, cx, Editor::go_to_hunk);
|
|
||||||
register_action(view, cx, Editor::go_to_prev_hunk);
|
|
||||||
register_action(view, cx, Editor::go_to_definition);
|
|
||||||
register_action(view, cx, Editor::go_to_definition_split);
|
|
||||||
register_action(view, cx, Editor::go_to_type_definition);
|
|
||||||
register_action(view, cx, Editor::go_to_type_definition_split);
|
|
||||||
register_action(view, cx, Editor::fold);
|
|
||||||
register_action(view, cx, Editor::fold_at);
|
|
||||||
register_action(view, cx, Editor::unfold_lines);
|
|
||||||
register_action(view, cx, Editor::unfold_at);
|
|
||||||
register_action(view, cx, Editor::fold_selected_ranges);
|
|
||||||
register_action(view, cx, Editor::show_completions);
|
|
||||||
register_action(view, cx, Editor::toggle_code_actions);
|
|
||||||
// on_action(cx, Editor::open_excerpts); todo!()
|
|
||||||
register_action(view, cx, Editor::toggle_soft_wrap);
|
|
||||||
register_action(view, cx, Editor::toggle_inlay_hints);
|
|
||||||
register_action(view, cx, Editor::reveal_in_finder);
|
|
||||||
register_action(view, cx, Editor::copy_path);
|
|
||||||
register_action(view, cx, Editor::copy_relative_path);
|
|
||||||
register_action(view, cx, Editor::copy_highlight_json);
|
|
||||||
register_action(view, cx, |editor, action, cx| {
|
|
||||||
editor
|
|
||||||
.format(action, cx)
|
|
||||||
.map(|task| task.detach_and_log_err(cx));
|
|
||||||
});
|
|
||||||
register_action(view, cx, Editor::restart_language_server);
|
|
||||||
register_action(view, cx, Editor::show_character_palette);
|
|
||||||
// on_action(cx, Editor::confirm_completion); todo!()
|
|
||||||
register_action(view, cx, |editor, action, cx| {
|
|
||||||
editor
|
|
||||||
.confirm_code_action(action, cx)
|
|
||||||
.map(|task| task.detach_and_log_err(cx));
|
|
||||||
});
|
|
||||||
register_action(view, cx, |editor, action, cx| {
|
|
||||||
editor
|
|
||||||
.rename(action, cx)
|
|
||||||
.map(|task| task.detach_and_log_err(cx));
|
|
||||||
});
|
|
||||||
register_action(view, cx, |editor, action, cx| {
|
|
||||||
editor
|
|
||||||
.confirm_rename(action, cx)
|
|
||||||
.map(|task| task.detach_and_log_err(cx));
|
|
||||||
});
|
|
||||||
register_action(view, cx, |editor, action, cx| {
|
|
||||||
editor
|
|
||||||
.find_all_references(action, cx)
|
|
||||||
.map(|task| task.detach_and_log_err(cx));
|
|
||||||
});
|
|
||||||
register_action(view, cx, Editor::next_copilot_suggestion);
|
|
||||||
register_action(view, cx, Editor::previous_copilot_suggestion);
|
|
||||||
register_action(view, cx, Editor::copilot_suggest);
|
|
||||||
register_action(view, cx, Editor::context_menu_first);
|
|
||||||
register_action(view, cx, Editor::context_menu_prev);
|
|
||||||
register_action(view, cx, Editor::context_menu_next);
|
|
||||||
register_action(view, cx, Editor::context_menu_last);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_action<T: Action>(
|
fn register_action<T: Action>(
|
||||||
view: &View<Editor>,
|
view: &View<Editor>,
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
|
|
|
@ -174,10 +174,7 @@ impl TextState {
|
||||||
|
|
||||||
let Some(lines) = text_system
|
let Some(lines) = text_system
|
||||||
.shape_text(
|
.shape_text(
|
||||||
&text,
|
&text, font_size, &runs, wrap_width, // Wrap if we know the width.
|
||||||
font_size,
|
|
||||||
&runs[..],
|
|
||||||
wrap_width, // Wrap if we know the width.
|
|
||||||
)
|
)
|
||||||
.log_err()
|
.log_err()
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue