pub struct PendingSyntheticHighlights {
pub map: Arc<Mutex<HashMap<BufferId, HighlightsUpdate>>>,
pub waker: Arc<Mutex<Option<Arc<Notify>>>>,
}Expand description
Shared state between async refresh tasks and the Editor’s tick drain.
The host registers the bare type, so reach it as
ctx.service::<PendingSyntheticHighlights>() — which already returns an
Arc, i.e. a PendingSyntheticHighlightsHandle to keep. Looking it up
as the handle type misses (the ServiceRegistry TypeId rule). Every
*_and_wake method fires the editor’s async_landed notify, so the
spans reach the screen without a keystroke (the inbound-wake rule).
One pending update per buffer. The map holds the latest undrained
update; a second store for the same buffer before the drain runs
replaces the first. Two splices in quick succession therefore need a
drain between them, or a Replace instead.
§Examples
use std::sync::Arc;
use lattice_core::BufferId;
use lattice_mode::{HighlightsOp, PendingSyntheticHighlights};
let pending = PendingSyntheticHighlights::new();
let wake = Arc::new(tokio::sync::Notify::new());
*pending.waker.lock().unwrap() = Some(wake.clone()); // the host does this at boot
pending.remove_at_and_wake(BufferId(3), 10, 2);
let update = pending.map.lock().unwrap().remove(&BufferId(3)).unwrap();
assert!(matches!(update.op, HighlightsOp::RemoveAt { start_line: 10, count: 2 }));Fields§
§map: Arc<Mutex<HashMap<BufferId, HighlightsUpdate>>>Undrained updates by buffer; the host’s tick drain empties it.
waker: Arc<Mutex<Option<Arc<Notify>>>>The editor’s async_landed notify, installed by the host at boot.
None (a test harness) means stores land but nothing wakes.
Implementations§
Source§impl PendingSyntheticHighlights
impl PendingSyntheticHighlights
Sourcepub fn store_and_wake(&self, buffer_id: BufferId, spans: Vec<Vec<StyledSpan>>)
pub fn store_and_wake(&self, buffer_id: BufferId, spans: Vec<Vec<StyledSpan>>)
Store per-line spans for buffer_id and fire the waker so the
Editor drains them on the next tick. Replaces any existing highlights
for the buffer.
Sourcepub fn store_refined_and_wake(
&self,
buffer_id: BufferId,
spans: Vec<Vec<StyledSpan>>,
refine: Vec<Vec<RefineSpan>>,
)
pub fn store_refined_and_wake( &self, buffer_id: BufferId, spans: Vec<Vec<StyledSpan>>, refine: Vec<Vec<RefineSpan>>, )
As Self::store_and_wake, carrying intra-line
refinement alongside the spans so both shift together (DR.3).
Sourcepub fn insert_at_and_wake(
&self,
buffer_id: BufferId,
start_line: u32,
spans: Vec<Vec<StyledSpan>>,
)
pub fn insert_at_and_wake( &self, buffer_id: BufferId, start_line: u32, spans: Vec<Vec<StyledSpan>>, )
Store per-line spans to be SPLICED IN to existing highlights at
a given line offset — lines before start_line keep their
spans; spans becomes the new content at start_line; every
line that was already at or after start_line shifts DOWN by
spans.len(). Use when the underlying text edit INSERTED
spans.len() new lines at start_line (e.g. toggle-diff
expanding inline content) — the highlight vector must grow and
shift in lockstep with the text, or every line after the
insertion point ends up painted with the wrong span.
Sourcepub fn insert_at_refined_and_wake(
&self,
buffer_id: BufferId,
start_line: u32,
spans: Vec<Vec<StyledSpan>>,
refine: Vec<Vec<RefineSpan>>,
)
pub fn insert_at_refined_and_wake( &self, buffer_id: BufferId, start_line: u32, spans: Vec<Vec<StyledSpan>>, refine: Vec<Vec<RefineSpan>>, )
Splice spans AND refinement at the same offset (DR.3).
The = toggle inserts an expansion’s lines mid-buffer; both
lists must shift by the same amount or the refinement ends up
over the wrong rows. Carrying them in one update and splicing
them with one implementation is what makes that impossible.
Sourcepub fn remove_at_and_wake(
&self,
buffer_id: BufferId,
start_line: u32,
count: usize,
)
pub fn remove_at_and_wake( &self, buffer_id: BufferId, start_line: u32, count: usize, )
Remove count lines of highlights starting at start_line,
shifting everything after them UP by count. The exact
inverse of Self::insert_at_and_wake — use when the
underlying text edit DELETED count lines at start_line
(e.g. toggle-diff collapsing inline content back down).