Display tooltip for select prev/next match buttons

This commit is contained in:
Antonio Scandurra 2022-06-16 14:37:33 +02:00
parent 649185da9c
commit 88d8696414
3 changed files with 57 additions and 15 deletions

View file

@ -141,6 +141,15 @@
]
}
},
{
"context": "BufferSearchBar",
"bindings": {
"escape": "buffer_search::Dismiss",
"cmd-f": "buffer_search::FocusEditor",
"enter": "search::SelectNextMatch",
"shift-enter": "search::SelectPrevMatch"
}
},
{
"context": "Pane",
"bindings": {
@ -152,15 +161,6 @@
"alt-cmd-r": "search::ToggleRegex"
}
},
{
"context": "BufferSearchBar",
"bindings": {
"escape": "buffer_search::Dismiss",
"cmd-f": "buffer_search::FocusEditor",
"enter": "search::SelectNextMatch",
"shift-enter": "search::SelectPrevMatch"
}
},
// Bindings from VS Code
{
"context": "Editor",

View file

@ -303,6 +303,20 @@ impl BufferSearchBar {
direction: Direction,
cx: &mut RenderContext<Self>,
) -> ElementBox {
let action: Box<dyn Action>;
let tooltip;
match direction {
Direction::Prev => {
action = Box::new(SelectPrevMatch);
tooltip = "Select Previous Match";
}
Direction::Next => {
action = Box::new(SelectNextMatch);
tooltip = "Select Next Match";
}
};
let tooltip_style = cx.global::<Settings>().theme.tooltip.clone();
enum NavButton {}
MouseEventHandler::new::<NavButton, _, _>(direction as usize, cx, |state, cx| {
let style = &cx
@ -316,11 +330,18 @@ impl BufferSearchBar {
.with_style(style.container)
.boxed()
})
.on_click(move |_, _, cx| match direction {
Direction::Prev => cx.dispatch_action(SelectPrevMatch),
Direction::Next => cx.dispatch_action(SelectNextMatch),
.on_click({
let action = action.boxed_clone();
move |_, _, cx| cx.dispatch_any_action(action.boxed_clone())
})
.with_cursor_style(CursorStyle::PointingHand)
.with_tooltip::<NavButton, _>(
direction as usize,
tooltip.to_string(),
Some(action),
tooltip_style,
cx,
)
.boxed()
}

View file

@ -693,6 +693,20 @@ impl ProjectSearchBar {
direction: Direction,
cx: &mut RenderContext<Self>,
) -> ElementBox {
let action: Box<dyn Action>;
let tooltip;
match direction {
Direction::Prev => {
action = Box::new(SelectPrevMatch);
tooltip = "Select Previous Match";
}
Direction::Next => {
action = Box::new(SelectNextMatch);
tooltip = "Select Next Match";
}
};
let tooltip_style = cx.global::<Settings>().theme.tooltip.clone();
enum NavButton {}
MouseEventHandler::new::<NavButton, _, _>(direction as usize, cx, |state, cx| {
let style = &cx
@ -706,11 +720,18 @@ impl ProjectSearchBar {
.with_style(style.container)
.boxed()
})
.on_click(move |_, _, cx| match direction {
Direction::Prev => cx.dispatch_action(SelectPrevMatch),
Direction::Next => cx.dispatch_action(SelectNextMatch),
.on_click({
let action = action.boxed_clone();
move |_, _, cx| cx.dispatch_any_action(action.boxed_clone())
})
.with_cursor_style(CursorStyle::PointingHand)
.with_tooltip::<NavButton, _>(
direction as usize,
tooltip.to_string(),
Some(action),
tooltip_style,
cx,
)
.boxed()
}