From 12c41a866db06d18b93074233423dd7d1dcf3039 Mon Sep 17 00:00:00 2001 From: Thomas Churchman Date: Thu, 28 Nov 2024 16:04:48 +0100 Subject: [PATCH] Fix off-by-one error in `PlainEditor::cursor_at` I believe the cursor should still land at index `self.buffer.len()` (logically following the last cluster). E.g., in https://github.com/linebender/xilem/pull/762, if used without this change, the selection can't span the last cluster using `cursor_at`. --- parley/src/layout/editor.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/parley/src/layout/editor.rs b/parley/src/layout/editor.rs index 0c912d5f..05eb0138 100644 --- a/parley/src/layout/editor.rs +++ b/parley/src/layout/editor.rs @@ -519,11 +519,7 @@ where fn cursor_at(&self, index: usize) -> Cursor { // FIXME: `Selection` should make this easier if index >= self.buffer.len() { - Cursor::from_byte_index( - &self.layout, - self.buffer.len().saturating_sub(1), - Affinity::Upstream, - ) + Cursor::from_byte_index(&self.layout, self.buffer.len(), Affinity::Upstream) } else { Cursor::from_byte_index(&self.layout, index, Affinity::Downstream) }