use std::cell::Cell;
thread_local! {
static PENDING_RESULT_FLUSH: Cell<bool> = const { Cell::new(false) };
}
pub fn mark_pending_result_flush() {
PENDING_RESULT_FLUSH.with(|flag| flag.set(true));
}
pub fn take_pending_result_flush() -> bool {
PENDING_RESULT_FLUSH.with(|flag| flag.replace(false))
}
pub fn has_pending_result_flush() -> bool {
PENDING_RESULT_FLUSH.with(|flag| flag.get())
}
thread_local! {
static FOCUS_ORPHANED: Cell<bool> = const { Cell::new(false) };
}
pub fn mark_focus_orphaned() {
FOCUS_ORPHANED.with(|flag| flag.set(true));
}
pub fn take_focus_orphaned() -> bool {
FOCUS_ORPHANED.with(|flag| flag.replace(false))
}
thread_local! {
static HOVER_ORPHANED: Cell<Option<u64>> = const { Cell::new(None) };
static LIVE_HOVER_LINK: Cell<(u64, u64)> = const { Cell::new((0, 0)) };
}
pub(crate) fn mark_hover_orphaned(root: u64) {
HOVER_ORPHANED.with(|slot| slot.set(Some(root)));
}
pub(crate) fn take_hover_orphaned(root: u64) -> bool {
HOVER_ORPHANED.with(|slot| {
if slot.get() == Some(root) {
slot.set(None);
true
} else {
false
}
})
}
pub(crate) fn set_live_hover_link(root: u64, epoch: u64) {
LIVE_HOVER_LINK.with(|slot| slot.set((root, epoch)));
}
pub(crate) fn live_hover_link_is(root: u64, epoch: u64) -> bool {
epoch != 0 && LIVE_HOVER_LINK.with(|slot| slot.get()) == (root, epoch)
}