(count: number, ctx: OperatorContext)
| 169 | * Execute delete character (x command). |
| 170 | */ |
| 171 | export function executeX(count: number, ctx: OperatorContext): void { |
| 172 | const from = ctx.cursor.offset |
| 173 | |
| 174 | if (from >= ctx.text.length) return |
| 175 | |
| 176 | // Advance by graphemes, not code units |
| 177 | let endCursor = ctx.cursor |
| 178 | for (let i = 0; i < count && !endCursor.isAtEnd(); i++) { |
| 179 | endCursor = endCursor.right() |
| 180 | } |
| 181 | const to = endCursor.offset |
| 182 | |
| 183 | const deleted = ctx.text.slice(from, to) |
| 184 | const newText = ctx.text.slice(0, from) + ctx.text.slice(to) |
| 185 | |
| 186 | ctx.setRegister(deleted, false) |
| 187 | ctx.setText(newText) |
| 188 | const maxOff = Math.max( |
| 189 | 0, |
| 190 | newText.length - (lastGrapheme(newText).length || 1), |
| 191 | ) |
| 192 | ctx.setOffset(Math.min(from, maxOff)) |
| 193 | ctx.recordChange({ type: 'x', count }) |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Execute replace character (r command). |
no test coverage detected