From a5ca7d04b0be96dc189f480afa30c30021e5e335 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Fri, 23 Oct 2026 17:13:32 -0400 Subject: [PATCH] Format Painter: walk only the paragraphs a text selection has An unclamped hostile selection end (text.select caret [1e18, 0]) made covered_paragraphs iterate for effectively forever. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/format.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/format.rs b/crates/engine/src/cmd/format.rs index 8bbc0c23..b92cd85d 100644 --- a/crates/engine/src/cmd/format.rs +++ b/crates/engine/src/cmd/format.rs @@ -1178,7 +1178,8 @@ fn covered_paragraphs(s: &Session) -> Vec { let Some(t) = &st.selection.text else { return vec![] }; let Some(body) = super::text::body_of(st, t) else { return vec![] }; let (a, b) = t.ordered(); - (a.0..=b.0) + // A hostile selection can point past the body: walk only the paragraphs it has. + (a.0..=b.0.min(body.paragraphs.len().saturating_sub(1))) .filter(|&pi| { let Some(para) = body.paragraphs.get(pi) else { return false }; let starts = pi > a.0 || a.1 == 0;