Skip to content

Commit

Permalink
Fix Clone definition for Injector
Browse files Browse the repository at this point in the history
Injectors detect that a Picker has been shut down / removed by checking
the shutdown atomic bool (which is shared with the Picker instance and
is set to `true` on Picker's Drop). Cloning Injector should create more
references to the Picker's atomic bool rather than creating new ones.
This should fix global search so that the WalkBuilder halts when the
picker is dropped.

This also fixes a small typo in the type "shutown -> shutdown"
  • Loading branch information
the-mikedavis committed Sep 6, 2023
1 parent e6cdc5f commit 76d7525
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ fn item_to_nucleo<T: Item>(item: T, editor_data: &T::Data) -> Option<(T, Utf32St
pub struct Injector<T: Item> {
dst: nucleo::Injector<T>,
editor_data: Arc<T::Data>,
shutown: Arc<AtomicBool>,
shutdown: Arc<AtomicBool>,
}

impl<T: Item> Clone for Injector<T> {
fn clone(&self) -> Self {
Injector {
dst: self.dst.clone(),
editor_data: self.editor_data.clone(),
shutown: Arc::new(AtomicBool::new(false)),
shutdown: self.shutdown.clone(),
}
}
}
Expand All @@ -165,7 +165,7 @@ pub struct InjectorShutdown;

impl<T: Item> Injector<T> {
pub fn push(&self, item: T) -> Result<(), InjectorShutdown> {
if self.shutown.load(atomic::Ordering::Relaxed) {
if self.shutdown.load(atomic::Ordering::Relaxed) {
return Err(InjectorShutdown);
}

Expand Down Expand Up @@ -214,7 +214,7 @@ impl<T: Item + 'static> Picker<T> {
let streamer = Injector {
dst: matcher.injector(),
editor_data: Arc::new(editor_data),
shutown: Arc::new(AtomicBool::new(false)),
shutdown: Arc::new(AtomicBool::new(false)),
};
(matcher, streamer)
}
Expand Down Expand Up @@ -249,7 +249,12 @@ impl<T: Item + 'static> Picker<T> {
injector: Injector<T>,
callback_fn: impl Fn(&mut Context, &T, Action) + 'static,
) -> Self {
Self::with(matcher, injector.editor_data, injector.shutown, callback_fn)
Self::with(
matcher,
injector.editor_data,
injector.shutdown,
callback_fn,
)
}

fn with(
Expand Down Expand Up @@ -287,7 +292,7 @@ impl<T: Item + 'static> Picker<T> {
Injector {
dst: self.matcher.injector(),
editor_data: self.editor_data.clone(),
shutown: self.shutdown.clone(),
shutdown: self.shutdown.clone(),
}
}

Expand Down

0 comments on commit 76d7525

Please sign in to comment.