Skip to content

Commit

Permalink
pickers v2: RequestRedrawOnDrop
Browse files Browse the repository at this point in the history
This fixes the changed files picker when used against a clean worktree.
Without it the running indicator does not disappear.
  • Loading branch information
the-mikedavis committed Mar 30, 2024
1 parent 899df55 commit cd20762
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
4 changes: 3 additions & 1 deletion helix-event/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
use anyhow::Result;
pub use cancel::{cancelable_future, cancelation, CancelRx, CancelTx};
pub use debounce::{send_blocking, AsyncHook};
pub use redraw::{lock_frame, redraw_requested, request_redraw, start_frame, RenderLockGuard};
pub use redraw::{
lock_frame, redraw_requested, request_redraw, start_frame, RenderLockGuard, RequestRedrawOnDrop,
};
pub use registry::Event;

mod cancel;
Expand Down
9 changes: 9 additions & 0 deletions helix-event/src/redraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ pub fn start_frame() {
pub fn lock_frame() -> RenderLockGuard {
RENDER_LOCK.read()
}

/// A zero sized type that requests a redraw via [request_redraw] when the type [Drop]s.
pub struct RequestRedrawOnDrop;

impl Drop for RequestRedrawOnDrop {
fn drop(&mut self) {
request_redraw();
}
}
9 changes: 9 additions & 0 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ pub struct Injector<T, D> {
editor_data: Arc<D>,
version: usize,
picker_version: Arc<AtomicUsize>,
/// A marker that requests a redraw when the injector drops.
/// This marker causes the "running" indicator to disappear when a background job
/// providing items is finished and drops. This could be wrapped in an [Arc] to ensure
/// that the redraw is only requested when all Injectors drop for a Picker (which removes
/// the "running" indicator) but the redraw handle is debounced so this is unnecessary.
_redraw: helix_event::RequestRedrawOnDrop,
}

impl<I, D> Clone for Injector<I, D> {
Expand All @@ -159,6 +165,7 @@ impl<I, D> Clone for Injector<I, D> {
editor_data: self.editor_data.clone(),
version: self.version,
picker_version: self.picker_version.clone(),
_redraw: helix_event::RequestRedrawOnDrop,
}
}
}
Expand Down Expand Up @@ -274,6 +281,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
editor_data: Arc::new(editor_data),
version: 0,
picker_version: Arc::new(AtomicUsize::new(0)),
_redraw: helix_event::RequestRedrawOnDrop,
};
(matcher, streamer)
}
Expand Down Expand Up @@ -376,6 +384,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
editor_data: self.editor_data.clone(),
version: self.version.load(atomic::Ordering::Relaxed),
picker_version: self.version.clone(),
_redraw: helix_event::RequestRedrawOnDrop,
}
}

Expand Down
7 changes: 2 additions & 5 deletions helix-term/src/ui/picker/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,8 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> AsyncHook for DynamicQu
if let Err(err) = get_options.await {
log::info!("Dynamic request failed: {err}");
}
// The picker's shows its running indicator when there are any active
// injectors. When we're done injecting new options, drop the injector
// and request a redraw to remove the running indicator.
drop(injector);
helix_event::request_redraw();
// NOTE: the Drop implementation of Injector will request a redraw when the
// injector falls out of scope here, clearing the "running" indicator.
});
})
}
Expand Down

0 comments on commit cd20762

Please sign in to comment.