Skip to content

Reset pending requests when moving GraphemeCursor - #186

Merged
Manishearth merged 1 commit into
unicode-rs:masterfrom
vera-rubin:fix/cursor-pending-requests
Oct 18, 2026
Merged

Manishearth merged 1 commit into
unicode-rs:masterfrom
vera-rubin:fix/cursor-pending-requests

Conversation

@vera-rubin

Copy link
Copy Markdown
Contributor

With s = "abcd", seeking to 2 while a chunk request is pending makes both next_boundary(s, 0) and prev_boundary(s, 0) return Ok(Some(2)). The documented forward search starts after the current position, so it should return 3, and the previous boundary is 1.

use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete::NextChunk};
let s = "abcd";
let mut cursor = GraphemeCursor::new(0, s.len(), true);
assert_eq!(cursor.next_boundary(&s[..1], 0), Err(NextChunk));
cursor.set_cursor(2);
assert_eq!(cursor.next_boundary(s, 0), Ok(Some(3)));

We clear the pending movement and pre-context state when the cursor changes position and document the cancellation behavior. A regression test covers all three input requests in both segmentation modes, and the full test suite passes.

Checkout: e77d186

— ChipLab

@Manishearth
Manishearth merged commit e445e10 into unicode-rs:master Oct 18, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants