Skip to content

Commit c96bf7b

Browse files
authored
Merge branch 'main' into tree-sitter-optional
2 parents bf10b5d + e51dbf8 commit c96bf7b

12 files changed

Lines changed: 310 additions & 216 deletions

File tree

crates/ui/src/highlighter/highlighter.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,9 @@ impl SyntaxHighlighter {
921921
if node_range.start > node_range.end {
922922
node_range.end = node_range.start;
923923
}
924+
if node_range.is_empty() {
925+
continue;
926+
}
924927

925928
styles.push((node_range, theme.style(name.as_ref()).unwrap_or_default()));
926929
}
@@ -960,6 +963,11 @@ pub(crate) fn unique_styles(
960963
total_range: &Range<usize>,
961964
styles: Vec<(Range<usize>, HighlightStyle)>,
962965
) -> Vec<(Range<usize>, HighlightStyle)> {
966+
let styles: Vec<_> = styles
967+
.into_iter()
968+
.filter(|(range, _)| !range.is_empty())
969+
.collect();
970+
963971
if styles.is_empty() {
964972
return styles;
965973
}
@@ -1392,5 +1400,11 @@ $x = 1;
13921400
(60..65, clean),
13931401
],
13941402
);
1403+
1404+
assert_unique_styles(
1405+
0..10,
1406+
vec![(2..2, red), (4..6, green)],
1407+
vec![(0..4, clean), (4..6, green), (6..10, clean)],
1408+
);
13951409
}
13961410
}

crates/ui/src/input/input.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use std::rc::Rc;
22

33
use gpui::prelude::FluentBuilder as _;
44
use gpui::{
5-
AnyElement, App, Context, DefiniteLength, Edges, EdgesRefinement, Entity, Hsla,
5+
AnyElement, App, DefiniteLength, Edges, EdgesRefinement, Entity, Hsla,
66
InteractiveElement as _, IntoElement, MouseButton, ParentElement as _, Rems, RenderOnce,
77
StyleRefinement, Styled, TextAlign, Window, div, px, relative,
88
};
99

1010
use crate::button::{Button, ButtonVariants as _};
1111
use crate::input::clear_button;
12-
use crate::menu::PopupMenu;
12+
use crate::native_menu::NativeMenu;
1313
use crate::spinner::Spinner;
1414
use crate::{ActiveTheme, Colorize, v_flex};
1515
use crate::{IconName, Size};
@@ -50,9 +50,8 @@ pub struct Input {
5050

5151
/// An optional context menu builder to allow a custom context menu on the input.
5252
///
53-
/// If set, this will override the built-in context menu.
54-
context_menu_builder:
55-
Option<Rc<dyn Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu>>,
53+
/// If set, this overrides the built-in context menu.
54+
context_menu_builder: Option<Rc<dyn Fn(NativeMenu, &mut Window, &mut App) -> NativeMenu>>,
5655
}
5756

5857
impl Sizable for Input {
@@ -159,10 +158,12 @@ impl Input {
159158
self
160159
}
161160

162-
/// Sets the context menu for the input.
161+
/// Sets a custom context menu builder for the input, shown as a native OS menu.
162+
///
163+
/// If set, this overrides the built-in right-click context menu.
163164
pub fn context_menu(
164165
mut self,
165-
f: impl Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu + 'static,
166+
f: impl Fn(NativeMenu, &mut Window, &mut App) -> NativeMenu + 'static,
166167
) -> Self {
167168
self.context_menu_builder = Some(Rc::new(f));
168169
self

crates/ui/src/input/lsp/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ impl InputState {
127127
handled = menu.handle_action(action, window, cx)
128128
});
129129
}
130-
ContextMenu::RightClick(..) => {}
131130
};
132131

133132
handled

crates/ui/src/input/popovers/context_menu.rs

Lines changed: 0 additions & 160 deletions
This file was deleted.

crates/ui/src/input/popovers/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
mod code_action_menu;
22
mod completion_menu;
3-
mod context_menu;
43
mod diagnostic_popover;
54
mod hover_popover;
65

76
pub(crate) use code_action_menu::*;
87
pub(crate) use completion_menu::*;
9-
pub(crate) use context_menu::*;
108
pub(crate) use diagnostic_popover::*;
119
pub(crate) use hover_popover::*;
1210

@@ -23,23 +21,20 @@ use crate::{
2321
pub(crate) enum ContextMenu {
2422
Completion(Entity<CompletionMenu>),
2523
CodeAction(Entity<CodeActionMenu>),
26-
RightClick(Entity<InputContextMenu>),
2724
}
2825

2926
impl ContextMenu {
3027
pub(crate) fn is_open(&self, cx: &App) -> bool {
3128
match self {
3229
ContextMenu::Completion(menu) => menu.read(cx).is_open(),
3330
ContextMenu::CodeAction(menu) => menu.read(cx).is_open(),
34-
ContextMenu::RightClick(menu) => menu.read(cx).is_open(),
3531
}
3632
}
3733

3834
pub(crate) fn render(&self) -> impl IntoElement {
3935
match self {
4036
ContextMenu::Completion(menu) => menu.clone().into_any_element(),
4137
ContextMenu::CodeAction(menu) => menu.clone().into_any_element(),
42-
ContextMenu::RightClick(menu) => menu.clone().into_any_element(),
4338
}
4439
}
4540
}

0 commit comments

Comments
 (0)