MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / visual_char_at

Function visual_char_at

src/text_input.rs:2316–2328  ·  view source on GitHub ↗

Get the visual character at a given visual position, or None if past end.

(raw: &str, visual_pos: usize)

Source from the content-addressed store, hash-verified

2314
2315 /// Get the visual character at a given visual position, or None if past end.
2316 pub fn visual_char_at(raw: &str, visual_pos: usize) -> Option<char> {
2317 let raw_pos = cursor_to_raw(raw, visual_pos);
2318 let chars: Vec<char> = raw.chars().collect();
2319 if raw_pos >= chars.len() {
2320 return None;
2321 }
2322 // If the char at raw_pos is `\`, the visible char is the next one
2323 if chars[raw_pos] == '\\' && raw_pos + 1 < chars.len() {
2324 Some(chars[raw_pos + 1])
2325 } else {
2326 Some(chars[raw_pos])
2327 }
2328 }
2329
2330 /// Strip all styling markup from a raw string, returning only visible text.
2331 pub fn strip_styling(raw: &str) -> String {

Callers

nothing calls this directly

Calls 1

cursor_to_rawFunction · 0.85

Tested by

no test coverage detected