Insert a (pre-escaped) string at the given visual position in the raw text. Returns the new raw string and the new visual cursor position after insertion. Enters empty style tags at the cursor boundary so typed text goes inside them.
(raw: &str, visual_pos: usize, insert: &str)
| 2077 | /// Returns the new raw string and the new visual cursor position after insertion. |
| 2078 | /// Enters empty style tags at the cursor boundary so typed text goes inside them. |
| 2079 | pub fn insert_at_visual(raw: &str, visual_pos: usize, insert: &str) -> (String, usize) { |
| 2080 | let raw_pos = cursor_to_raw_for_insertion(raw, visual_pos); |
| 2081 | let byte_pos = super::char_index_to_byte(raw, raw_pos); |
| 2082 | let mut new_raw = String::with_capacity(raw.len() + insert.len()); |
| 2083 | new_raw.push_str(&raw[..byte_pos]); |
| 2084 | new_raw.push_str(insert); |
| 2085 | new_raw.push_str(&raw[byte_pos..]); |
| 2086 | let inserted_visual = cursor_len(insert); |
| 2087 | (new_raw, visual_pos + inserted_visual) |
| 2088 | } |
| 2089 | |
| 2090 | /// Delete visible characters in the visual range `[visual_start, visual_end)`. |
| 2091 | /// Preserves all style tag structure (`{name|`, `}`) and only removes the content |