Apply a sorted (reverse order) list of non-overlapping `TextEdit`s to a string, returning the modified content.
(content: &str, edits: &[TextEdit])
| 178 | /// Apply a sorted (reverse order) list of non-overlapping `TextEdit`s |
| 179 | /// to a string, returning the modified content. |
| 180 | fn apply_text_edits(content: &str, edits: &[TextEdit]) -> String { |
| 181 | let mut result = content.to_string(); |
| 182 | |
| 183 | for edit in edits { |
| 184 | let start = position_to_byte_offset(&result, edit.range.start); |
| 185 | let end = position_to_byte_offset(&result, edit.range.end); |
| 186 | |
| 187 | if start <= end && end <= result.len() { |
| 188 | result.replace_range(start..end, &edit.new_text); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | result |
| 193 | } |
| 194 | |
| 195 | /// Run the fix command and return the process exit code. |
| 196 | /// |