editor: Move code actions menu closer to the indicator when it is deployed via click (#11214)

Before:

![image](https://github.com/zed-industries/zed/assets/24362066/98d633a7-c982-4522-b4dc-b944b70b8081)

After: 

![image](https://github.com/zed-industries/zed/assets/24362066/79931e12-0e6c-4ece-b734-5af7d02f7e50)

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-04-30 18:51:20 +02:00 committed by GitHub
parent 713c314d67
commit ada2791fa3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 13 deletions

View file

@ -764,10 +764,10 @@ impl ContextMenu {
max_height: Pixels,
workspace: Option<WeakView<Workspace>>,
cx: &mut ViewContext<Editor>,
) -> (DisplayPoint, AnyElement) {
) -> (ContextMenuOrigin, AnyElement) {
match self {
ContextMenu::Completions(menu) => (
cursor_position,
ContextMenuOrigin::EditorPoint(cursor_position),
menu.render(style, max_height, workspace, cx),
),
ContextMenu::CodeActions(menu) => menu.render(cursor_position, style, max_height, cx),
@ -775,6 +775,11 @@ impl ContextMenu {
}
}
enum ContextMenuOrigin {
EditorPoint(DisplayPoint),
GutterIndicator(u32),
}
#[derive(Clone)]
struct CompletionsMenu {
id: CompletionId,
@ -1208,11 +1213,11 @@ impl CodeActionsMenu {
fn render(
&self,
mut cursor_position: DisplayPoint,
cursor_position: DisplayPoint,
_style: &EditorStyle,
max_height: Pixels,
cx: &mut ViewContext<Editor>,
) -> (DisplayPoint, AnyElement) {
) -> (ContextMenuOrigin, AnyElement) {
let actions = self.actions.clone();
let selected_item = self.selected_item;
@ -1277,10 +1282,11 @@ impl CodeActionsMenu {
)
.into_any_element();
if self.deployed_from_indicator {
*cursor_position.column_mut() = 0;
}
let cursor_position = if self.deployed_from_indicator {
ContextMenuOrigin::GutterIndicator(cursor_position.row())
} else {
ContextMenuOrigin::EditorPoint(cursor_position)
};
(cursor_position, element)
}
}
@ -4247,13 +4253,13 @@ impl Editor {
.map_or(false, |menu| menu.visible())
}
pub fn render_context_menu(
fn render_context_menu(
&self,
cursor_position: DisplayPoint,
style: &EditorStyle,
max_height: Pixels,
cx: &mut ViewContext<Editor>,
) -> Option<(DisplayPoint, AnyElement)> {
) -> Option<(ContextMenuOrigin, AnyElement)> {
self.context_menu.read().as_ref().map(|menu| {
menu.render(
cursor_position,