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

Function delete_content_range

src/text_input.rs:2494–2549  ·  view source on GitHub ↗

Delete content characters in `[content_start, content_end)` from the raw styled string, preserving all structural/tag characters.

(raw: &str, content_start: usize, content_end: usize)

Source from the content-addressed store, hash-verified

2492 /// Delete content characters in `[content_start, content_end)` from the
2493 /// raw styled string, preserving all structural/tag characters.
2494 pub fn delete_content_range(raw: &str, content_start: usize, content_end: usize) -> String {
2495 if content_start >= content_end {
2496 return raw.to_string();
2497 }
2498
2499 let chars: Vec<char> = raw.chars().collect();
2500 let len = chars.len();
2501 let mut result = String::with_capacity(raw.len());
2502 let mut content = 0usize;
2503 let mut i = 0;
2504 let mut in_style_def = false;
2505
2506 while i < len {
2507 let c = chars[i];
2508
2509 match c {
2510 '\\' if !in_style_def && i + 1 < len => {
2511 let in_range = content >= content_start && content < content_end;
2512 if !in_range {
2513 result.push(c);
2514 result.push(chars[i + 1]);
2515 }
2516 content += 1;
2517 i += 2;
2518 }
2519 '{' if !in_style_def => {
2520 in_style_def = true;
2521 result.push(c);
2522 i += 1;
2523 }
2524 '|' if in_style_def => {
2525 in_style_def = false;
2526 result.push(c);
2527 i += 1;
2528 }
2529 '}' if !in_style_def => {
2530 result.push(c);
2531 i += 1;
2532 }
2533 _ if in_style_def => {
2534 result.push(c);
2535 i += 1;
2536 }
2537 _ => {
2538 let in_range = content >= content_start && content < content_end;
2539 if !in_range {
2540 result.push(c);
2541 }
2542 content += 1;
2543 i += 1;
2544 }
2545 }
2546 }
2547
2548 result
2549 }
2550
2551 /// Find word boundary left in visual space.

Callers 5

backspace_styledMethod · 0.85
delete_forward_styledMethod · 0.85
backspace_word_styledMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected