( op: Operator, from: number, to: number, ctx: OperatorContext, linewise: boolean = false, )
| 491 | } |
| 492 | |
| 493 | function applyOperator( |
| 494 | op: Operator, |
| 495 | from: number, |
| 496 | to: number, |
| 497 | ctx: OperatorContext, |
| 498 | linewise: boolean = false, |
| 499 | ): void { |
| 500 | let content = ctx.text.slice(from, to) |
| 501 | // Ensure linewise content ends with newline for paste detection |
| 502 | if (linewise && !content.endsWith('\n')) { |
| 503 | content = content + '\n' |
| 504 | } |
| 505 | ctx.setRegister(content, linewise) |
| 506 | |
| 507 | if (op === 'yank') { |
| 508 | ctx.setOffset(from) |
| 509 | } else if (op === 'delete') { |
| 510 | const newText = ctx.text.slice(0, from) + ctx.text.slice(to) |
| 511 | ctx.setText(newText) |
| 512 | const maxOff = Math.max( |
| 513 | 0, |
| 514 | newText.length - (lastGrapheme(newText).length || 1), |
| 515 | ) |
| 516 | ctx.setOffset(Math.min(from, maxOff)) |
| 517 | } else if (op === 'change') { |
| 518 | const newText = ctx.text.slice(0, from) + ctx.text.slice(to) |
| 519 | ctx.setText(newText) |
| 520 | ctx.enterInsert(from) |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | export function executeOperatorG( |
| 525 | op: Operator, |
no test coverage detected