( direction: 'above' | 'below', ctx: OperatorContext, )
| 395 | * Execute open line (o/O command). |
| 396 | */ |
| 397 | export function executeOpenLine( |
| 398 | direction: 'above' | 'below', |
| 399 | ctx: OperatorContext, |
| 400 | ): void { |
| 401 | const text = ctx.text |
| 402 | const lines = text.split('\n') |
| 403 | const { line: currentLine } = ctx.cursor.getPosition() |
| 404 | |
| 405 | const insertLine = direction === 'below' ? currentLine + 1 : currentLine |
| 406 | const newLines = [ |
| 407 | ...lines.slice(0, insertLine), |
| 408 | '', |
| 409 | ...lines.slice(insertLine), |
| 410 | ] |
| 411 | |
| 412 | const newText = newLines.join('\n') |
| 413 | ctx.setText(newText) |
| 414 | ctx.enterInsert(getLineStartOffset(newLines, insertLine)) |
| 415 | ctx.recordChange({ type: 'openLine', direction }) |
| 416 | } |
| 417 | |
| 418 | // ============================================================================ |
| 419 | // Internal Helpers |
no test coverage detected