Hold a weak handle when watching settings in WrapMap

This commit is contained in:
Nathan Sobo
2021-09-07 22:08:40 -06:00
parent 8262afd1fb
commit 0fb59ee491
+7 -6
View File
@@ -80,19 +80,20 @@ impl WrapMap {
wrap_width: Option<f32>,
cx: &mut ModelContext<Self>,
) -> Self {
let _watch_settings = cx.spawn({
let _watch_settings = cx.spawn_weak({
let mut prev_font = (
settings.borrow().buffer_font_size,
settings.borrow().buffer_font_family,
);
let mut settings = settings.clone();
move |this, mut cx| async move {
let _ = settings.recv().await;
while let Some(settings) = settings.recv().await {
let font = (settings.buffer_font_size, settings.buffer_font_family);
if font != prev_font {
prev_font = font;
this.update(&mut cx, |this, cx| this.rewrap(cx));
if let Some(this) = this.upgrade(&cx) {
let font = (settings.buffer_font_size, settings.buffer_font_family);
if font != prev_font {
prev_font = font;
this.update(&mut cx, |this, cx| this.rewrap(cx));
}
}
}
}