Give hover state to picker items, keystrokes in command palette
This commit is contained in:
parent
a60c75e343
commit
8481834847
20 changed files with 269 additions and 288 deletions
|
@ -1,12 +1,14 @@
|
|||
use editor::Editor;
|
||||
use gpui::{
|
||||
elements::{
|
||||
ChildView, EventHandler, Flex, Label, ParentElement, ScrollTarget, UniformList,
|
||||
UniformListState,
|
||||
ChildView, Flex, Label, MouseEventHandler, MouseState, ParentElement, ScrollTarget,
|
||||
UniformList, UniformListState,
|
||||
},
|
||||
geometry::vector::{vec2f, Vector2F},
|
||||
keymap, AppContext, Axis, Element, ElementBox, Entity, MutableAppContext, RenderContext, Task,
|
||||
View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
keymap,
|
||||
platform::CursorStyle,
|
||||
AppContext, Axis, Element, ElementBox, Entity, MutableAppContext, RenderContext, Task, View,
|
||||
ViewContext, ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use settings::Settings;
|
||||
use std::cmp;
|
||||
|
@ -29,7 +31,13 @@ pub trait PickerDelegate: View {
|
|||
fn update_matches(&mut self, query: String, cx: &mut ViewContext<Self>) -> Task<()>;
|
||||
fn confirm(&mut self, cx: &mut ViewContext<Self>);
|
||||
fn dismiss(&mut self, cx: &mut ViewContext<Self>);
|
||||
fn render_match(&self, ix: usize, selected: bool, cx: &AppContext) -> ElementBox;
|
||||
fn render_match(
|
||||
&self,
|
||||
ix: usize,
|
||||
state: &MouseState,
|
||||
selected: bool,
|
||||
cx: &AppContext,
|
||||
) -> ElementBox;
|
||||
fn center_selection_after_match_updates(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
@ -73,18 +81,18 @@ impl<D: PickerDelegate> View for Picker<D> {
|
|||
self.list_state.clone(),
|
||||
match_count,
|
||||
move |mut range, items, cx| {
|
||||
let cx = cx.as_ref();
|
||||
let delegate = delegate.upgrade(cx).unwrap();
|
||||
let delegate = delegate.read(cx);
|
||||
let selected_ix = delegate.selected_index();
|
||||
range.end = cmp::min(range.end, delegate.match_count());
|
||||
let selected_ix = delegate.read(cx).selected_index();
|
||||
range.end = cmp::min(range.end, delegate.read(cx).match_count());
|
||||
items.extend(range.map(move |ix| {
|
||||
EventHandler::new(delegate.render_match(ix, ix == selected_ix, cx))
|
||||
.on_mouse_down(move |cx| {
|
||||
cx.dispatch_action(SelectIndex(ix));
|
||||
true
|
||||
})
|
||||
.boxed()
|
||||
MouseEventHandler::new::<D, _, _>(ix, cx, |state, cx| {
|
||||
delegate
|
||||
.read(cx)
|
||||
.render_match(ix, state, ix == selected_ix, cx)
|
||||
})
|
||||
.on_mouse_down(move |cx| cx.dispatch_action(SelectIndex(ix)))
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.boxed()
|
||||
}));
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue