Right press: one alignment pass, latest press wins
CI / platforms (windows-latest) (push) Failing after 10s
CI / site (push) Successful in 22s
CI / crate (push) Failing after 12m14s
CI / platforms (ubuntu-24.04) (push) Canceled after 0s

drawn_at aligns each source piece once instead of re-reading the span
for every drawn byte, so a right press near a long paragraph's start
stays linear. A newer press drops an older pending open-block lookup.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-14 21:40:55 -04:00
1 parent a4bf6965f9
commit 2b8bd9fcf3
5 files changed
+99 -19

No files matched your search

+7 -8
View File
@@ -111,6 +111,7 @@ impl MarkdownDocument {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.pressed += 1;
let block = match ix.map(|ix| self.parsed.blocks.get(ix)) {
Some(None) => return log::warn!("markdown document: a press on a block read away"),
block => block.flatten(),
@@ -170,12 +171,17 @@ impl MarkdownDocument {
let pressed = open.input.read(cx).offset_for_point(position);
let taken = self.snapshot(cx);
let (full, offset, _) = taken.clone();
self.pressed += 1;
let press = self.pressed;
cx.spawn(async move |document, cx| {
let target = cx
.background_spawn(async move { target_at(&full, offset + pressed) })
.await;
document
.update(cx, |document, cx| {
if document.pressed != press {
return log::info!("markdown document: a newer press came first");
}
if document.open.is_none() || document.snapshot(cx) != taken {
return log::info!("markdown document: the pressed block changed first");
}
@@ -291,14 +297,7 @@ fn drawn_link(nodes: &[&Node], text: &str, at: usize) -> Option<Option<String>>
}
_ => None,
})?;
let drawn = (0..inline.text.len())
.filter(|ix| inline.text.is_char_boundary(*ix))
.rev()
.find(|ix| {
inline
.source_at(text, *ix)
.is_some_and(|source| source <= at)
})?;
let drawn = inline.drawn_at(text, at)?;
let link = (inline.links.iter()).find(|(range, _)| range.contains(&drawn));
Some(link.map(|(_, url)| url.clone()))
}