pub fn reconcile_cursor_position(
old_text: &str,
new_text: &str,
old_cursor_byte: usize,
) -> usizeExpand description
Reconcile cursor byte position when text content changes.
This function maps a cursor position from old text to new text, preserving the cursor’s logical position as much as possible:
- If cursor is in unchanged prefix → stays at same byte offset
- If cursor is in unchanged suffix → adjusts by length difference
- If cursor is in changed region → places at end of new content
§Arguments
old_text- The previous text contentnew_text- The new text contentold_cursor_byte- Cursor byte offset in old text
§Returns
The reconciled cursor byte offset in new text
§Example
ⓘ
let old_text = "Hello";
let new_text = "Hello World";
let old_cursor = 5; // cursor at end of "Hello"
let new_cursor = reconcile_cursor_position(old_text, new_text, old_cursor);
assert_eq!(new_cursor, 5); // cursor stays at same position (prefix unchanged)