Skip to content

Commit

Permalink
Fix off-by-one error in PlainEditor::cursor_at
Browse files Browse the repository at this point in the history
I believe the cursor should still land at index `self.buffer.len()`
(logically following the last cluster).

E.g., in linebender/xilem#762, if used without this
change, the selection can't span the last cluster using `cursor_at`.
  • Loading branch information
tomcur committed Nov 28, 2024
1 parent c0d158b commit 12c41a8
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions parley/src/layout/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 12c41a8

Please sign in to comment.