Start on hover popover

This commit is contained in:
Antonio Scandurra 2023-11-27 18:56:37 +01:00
parent cd4ea344a6
commit a5951df21f
3 changed files with 968 additions and 986 deletions

View file

@ -530,8 +530,6 @@ pub fn init(cx: &mut AppContext) {
// cx.register_action_type(Editor::context_menu_next); // cx.register_action_type(Editor::context_menu_next);
// cx.register_action_type(Editor::context_menu_last); // cx.register_action_type(Editor::context_menu_last);
hover_popover::init(cx);
workspace::register_project_item::<Editor>(cx); workspace::register_project_item::<Editor>(cx);
workspace::register_followable_item::<Editor>(cx); workspace::register_followable_item::<Editor>(cx);
workspace::register_deserializable_item::<Editor>(cx); workspace::register_deserializable_item::<Editor>(cx);

View file

@ -5,7 +5,9 @@ use crate::{
}, },
editor_settings::ShowScrollbar, editor_settings::ShowScrollbar,
git::{diff_hunk_to_display, DisplayDiffHunk}, git::{diff_hunk_to_display, DisplayDiffHunk},
hover_popover::hover_at, hover_popover::{
self, hover_at, HOVER_POPOVER_GAP, MIN_POPOVER_CHARACTER_WIDTH, MIN_POPOVER_LINE_HEIGHT,
},
link_go_to_definition::{ link_go_to_definition::{
go_to_fetched_definition, go_to_fetched_type_definition, update_go_to_definition_link, go_to_fetched_definition, go_to_fetched_type_definition, update_go_to_definition_link,
update_inlay_link_and_hover_points, GoToDefinitionTrigger, update_inlay_link_and_hover_points, GoToDefinitionTrigger,
@ -257,6 +259,7 @@ impl EditorElement {
// on_action(cx, Editor::open_excerpts); todo!() // on_action(cx, Editor::open_excerpts); todo!()
register_action(view, cx, Editor::toggle_soft_wrap); register_action(view, cx, Editor::toggle_soft_wrap);
register_action(view, cx, Editor::toggle_inlay_hints); register_action(view, cx, Editor::toggle_inlay_hints);
register_action(view, cx, hover_popover::hover);
register_action(view, cx, Editor::reveal_in_finder); register_action(view, cx, Editor::reveal_in_finder);
register_action(view, cx, Editor::copy_path); register_action(view, cx, Editor::copy_path);
register_action(view, cx, Editor::copy_relative_path); register_action(view, cx, Editor::copy_relative_path);
@ -1024,8 +1027,8 @@ impl EditorElement {
} }
}); });
if let Some((position, mut context_menu)) = layout.context_menu.take() { cx.with_z_index(1, |cx| {
cx.with_z_index(1, |cx| { if let Some((position, mut context_menu)) = layout.context_menu.take() {
let available_space = let available_space =
size(AvailableSpace::MinContent, AvailableSpace::MinContent); size(AvailableSpace::MinContent, AvailableSpace::MinContent);
let context_menu_size = context_menu.measure(available_space, cx); let context_menu_size = context_menu.measure(available_space, cx);
@ -1053,80 +1056,72 @@ impl EditorElement {
} }
context_menu.draw(list_origin, available_space, cx); context_menu.draw(list_origin, available_space, cx);
}) }
}
// if let Some((position, hover_popovers)) = layout.hover_popovers.as_mut() { if let Some((position, mut hover_popovers)) = layout.hover_popovers.take() {
// cx.scene().push_stacking_context(None, None); let available_space =
size(AvailableSpace::MinContent, AvailableSpace::MinContent);
// cx.scene().push_stacking_context(None, None);
// // This is safe because we check on layout whether the required row is available // This is safe because we check on layout whether the required row is available
// let hovered_row_layout = let hovered_row_layout = &layout.position_map.line_layouts
// &layout.position_map.line_layouts[(position.row() - start_row) as usize].line; [(position.row() - start_row) as usize]
.line;
// // Minimum required size: Take the first popover, and add 1.5 times the minimum popover // Minimum required size: Take the first popover, and add 1.5 times the minimum popover
// // height. This is the size we will use to decide whether to render popovers above or below // height. This is the size we will use to decide whether to render popovers above or below
// // the hovered line. // the hovered line.
// let first_size = hover_popovers[0].size(); let first_size = hover_popovers[0].measure(available_space, cx);
// let height_to_reserve = first_size.y let height_to_reserve = first_size.height
// + 1.5 * MIN_POPOVER_LINE_HEIGHT as f32 * layout.position_map.line_height; + 1.5 * MIN_POPOVER_LINE_HEIGHT * layout.position_map.line_height;
// // Compute Hovered Point // Compute Hovered Point
// let x = hovered_row_layout.x_for_index(position.column() as usize) - scroll_left; let x = hovered_row_layout.x_for_index(position.column() as usize)
// let y = position.row() as f32 * layout.position_map.line_height - scroll_top; - layout.position_map.scroll_position.x;
// let hovered_point = content_origin + point(x, y); let y = position.row() as f32 * layout.position_map.line_height
- layout.position_map.scroll_position.y;
let hovered_point = content_origin + point(x, y);
// if hovered_point.y - height_to_reserve > 0.0 { if hovered_point.y - height_to_reserve > Pixels::ZERO {
// // There is enough space above. Render popovers above the hovered point // There is enough space above. Render popovers above the hovered point
// let mut current_y = hovered_point.y; let mut current_y = hovered_point.y;
// for hover_popover in hover_popovers { for mut hover_popover in hover_popovers {
// let size = hover_popover.size(); let size = hover_popover.measure(available_space, cx);
// let mut popover_origin = point(hovered_point.x, current_y - size.y); let mut popover_origin =
point(hovered_point.x, current_y - size.height);
// let x_out_of_bounds = bounds.max_x - (popover_origin.x + size.x); let x_out_of_bounds =
// if x_out_of_bounds < 0.0 { text_bounds.upper_right().x - (popover_origin.x + size.width);
// popover_origin.set_x(popover_origin.x + x_out_of_bounds); if x_out_of_bounds < Pixels::ZERO {
// } popover_origin.x = popover_origin.x + x_out_of_bounds;
}
// hover_popover.paint( hover_popover.draw(popover_origin, available_space, cx);
// popover_origin,
// Bounds::<Pixels>::from_points(
// gpui::Point::<Pixels>::zero(),
// point(f32::MAX, f32::MAX),
// ), // Let content bleed outside of editor
// editor,
// cx,
// );
// current_y = popover_origin.y - HOVER_POPOVER_GAP; current_y = popover_origin.y - HOVER_POPOVER_GAP;
// } }
// } else { } else {
// // There is not enough space above. Render popovers below the hovered point // There is not enough space above. Render popovers below the hovered point
// let mut current_y = hovered_point.y + layout.position_map.line_height; let mut current_y = hovered_point.y + layout.position_map.line_height;
// for hover_popover in hover_popovers { for mut hover_popover in hover_popovers {
// let size = hover_popover.size(); let size = hover_popover.measure(available_space, cx);
// let mut popover_origin = point(hovered_point.x, current_y); let mut popover_origin = point(hovered_point.x, current_y);
// let x_out_of_bounds = bounds.max_x - (popover_origin.x + size.x); let x_out_of_bounds =
// if x_out_of_bounds < 0.0 { text_bounds.upper_right().x - (popover_origin.x + size.width);
// popover_origin.set_x(popover_origin.x + x_out_of_bounds); if x_out_of_bounds < Pixels::ZERO {
// } popover_origin.x = popover_origin.x + x_out_of_bounds;
}
// hover_popover.paint( hover_popover.draw(popover_origin, available_space, cx);
// popover_origin,
// Bounds::<Pixels>::from_points(
// gpui::Point::<Pixels>::zero(),
// point(f32::MAX, f32::MAX),
// ), // Let content bleed outside of editor
// editor,
// cx,
// );
// current_y = popover_origin.y + size.y + HOVER_POPOVER_GAP; current_y = popover_origin.y + size.height + HOVER_POPOVER_GAP;
// } }
// } }
// cx.scene().pop_stacking_context(); // cx.scene().pop_stacking_context();
// } }
})
}, },
) )
} }
@ -1992,15 +1987,23 @@ impl EditorElement {
} }
let visible_rows = start_row..start_row + line_layouts.len() as u32; let visible_rows = start_row..start_row + line_layouts.len() as u32;
// todo!("hover") let max_size = size(
// let mut hover = editor.hover_state.render( (120. * em_width) // Default size
// &snapshot, .min(bounds.size.width / 2.) // Shrink to half of the editor width
// &style, .max(MIN_POPOVER_CHARACTER_WIDTH * em_width), // Apply minimum width of 20 characters
// visible_rows, (16. * line_height) // Default size
// editor.workspace.as_ref().map(|(w, _)| w.clone()), .min(bounds.size.height / 2.) // Shrink to half of the editor height
// cx, .max(MIN_POPOVER_LINE_HEIGHT * line_height), // Apply minimum height of 4 lines
// ); );
// let mode = editor.mode;
let mut hover = editor.hover_state.render(
&snapshot,
&style,
visible_rows,
max_size,
editor.workspace.as_ref().map(|(w, _)| w.clone()),
cx,
);
let mut fold_indicators = cx.with_element_id(Some("gutter_fold_indicators"), |cx| { let mut fold_indicators = cx.with_element_id(Some("gutter_fold_indicators"), |cx| {
editor.render_fold_indicators( editor.render_fold_indicators(
@ -2013,27 +2016,6 @@ impl EditorElement {
) )
}); });
// todo!("hover popovers")
// if let Some((_, hover_popovers)) = hover.as_mut() {
// for hover_popover in hover_popovers.iter_mut() {
// hover_popover.layout(
// SizeConstraint {
// min: gpui::Point::<Pixels>::zero(),
// max: point(
// (120. * em_width) // Default size
// .min(size.x / 2.) // Shrink to half of the editor width
// .max(MIN_POPOVER_CHARACTER_WIDTH * em_width), // Apply minimum width of 20 characters
// (16. * line_height) // Default size
// .min(size.y / 2.) // Shrink to half of the editor height
// .max(MIN_POPOVER_LINE_HEIGHT * line_height), // Apply minimum height of 4 lines
// ),
// },
// editor,
// cx,
// );
// }
// }
let invisible_symbol_font_size = font_size / 2.; let invisible_symbol_font_size = font_size / 2.;
let tab_invisible = cx let tab_invisible = cx
.text_system() .text_system()
@ -2102,7 +2084,7 @@ impl EditorElement {
fold_indicators, fold_indicators,
tab_invisible, tab_invisible,
space_invisible, space_invisible,
// hover_popovers: hover, hover_popovers: hover,
} }
}) })
} }
@ -3287,7 +3269,7 @@ pub struct LayoutState {
max_row: u32, max_row: u32,
context_menu: Option<(DisplayPoint, AnyElement)>, context_menu: Option<(DisplayPoint, AnyElement)>,
code_actions_indicator: Option<CodeActionsIndicator>, code_actions_indicator: Option<CodeActionsIndicator>,
// hover_popovers: Option<(DisplayPoint, Vec<AnyElement>)>, hover_popovers: Option<(DisplayPoint, Vec<AnyElement>)>,
fold_indicators: Vec<Option<IconButton>>, fold_indicators: Vec<Option<IconButton>>,
tab_invisible: ShapedLine, tab_invisible: ShapedLine,
space_invisible: ShapedLine, space_invisible: ShapedLine,

File diff suppressed because it is too large Load diff