Function select_line_at

Source
pub fn select_line_at(text: &str, byte: usize) -> Range<usize>
Expand description

Returns the logical line containing a UTF-8 byte offset, excluding \n.

Out-of-range offsets clamp to EOF and offsets inside a multi-byte character clamp backward to its start. For a trailing newline, EOF selects the empty final line.

ยงExamples

use ailloli_ui_editor::input::selection::select_line_at;

assert_eq!(select_line_at("first\nsecond\n", 8), 6..12);
assert_eq!(select_line_at("first\nsecond\n", usize::MAX), 13..13);