feat: syntax highlighting for diff view
This commit is contained in:
27
src/query.rs
27
src/query.rs
@@ -1,4 +1,4 @@
|
||||
use gpui::{AppContext, BorrowAppContext};
|
||||
use gpui::BorrowAppContext;
|
||||
use std::{any::Any, borrow::Cow, collections::HashMap, marker::PhantomData, ops::Deref};
|
||||
|
||||
pub(crate) trait QueryFn: Clone + 'static {
|
||||
@@ -187,19 +187,28 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn observe_query<E, F>(
|
||||
query: &Entity<F>,
|
||||
mut on_notify: impl FnMut(&mut E, &Entity<F>, &mut gpui::Context<E>) + 'static,
|
||||
cx: &mut gpui::Context<E>,
|
||||
) -> gpui::Subscription
|
||||
pub fn watch_query<E, F, H>(query: &Entity<F>, on_notify: H, cx: &mut gpui::Context<E>) -> gpui::Subscription
|
||||
where
|
||||
E: 'static,
|
||||
F: QueryFn,
|
||||
H: Fn(&mut E, &Entity<F>, &mut gpui::Context<E>) + Clone + 'static,
|
||||
{
|
||||
let q = query.clone();
|
||||
cx.observe(&query, move |this, _, cx| {
|
||||
on_notify(this, &q, cx);
|
||||
let observed_query = query.clone();
|
||||
let sub = cx.observe(query, {
|
||||
let on_notify = on_notify.clone();
|
||||
move |this, _, cx| on_notify(this, &observed_query, cx)
|
||||
});
|
||||
|
||||
let initial_query = query.clone();
|
||||
cx.spawn({
|
||||
let on_notify = on_notify.clone();
|
||||
async move |weak, cx| {
|
||||
let _ = weak.update(cx, |this, cx| on_notify(this, &initial_query, cx));
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
sub
|
||||
}
|
||||
|
||||
// ================= Store ==================
|
||||
|
||||
Reference in New Issue
Block a user