( char: string, count: number, ctx: OperatorContext, )
| 197 | * Execute replace character (r command). |
| 198 | */ |
| 199 | export function executeReplace( |
| 200 | char: string, |
| 201 | count: number, |
| 202 | ctx: OperatorContext, |
| 203 | ): void { |
| 204 | let offset = ctx.cursor.offset |
| 205 | let newText = ctx.text |
| 206 | |
| 207 | for (let i = 0; i < count && offset < newText.length; i++) { |
| 208 | const graphemeLen = firstGrapheme(newText.slice(offset)).length || 1 |
| 209 | newText = |
| 210 | newText.slice(0, offset) + char + newText.slice(offset + graphemeLen) |
| 211 | offset += char.length |
| 212 | } |
| 213 | |
| 214 | ctx.setText(newText) |
| 215 | ctx.setOffset(Math.max(0, offset - char.length)) |
| 216 | ctx.recordChange({ type: 'replace', char, count }) |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Execute toggle case (~ command). |
no test coverage detected