()
| 377 | } |
| 378 | |
| 379 | down(): Cursor { |
| 380 | const { line, column } = this.getPosition() |
| 381 | if (line >= this.measuredText.lineCount - 1) { |
| 382 | return this |
| 383 | } |
| 384 | |
| 385 | // If there is no next line, stay on the current line, |
| 386 | // and let the caller handle it (e.g. for prompt input, |
| 387 | // we move to the next history entry) |
| 388 | const nextLine = this.measuredText.getWrappedText()[line + 1] |
| 389 | if (nextLine === undefined) { |
| 390 | return this |
| 391 | } |
| 392 | |
| 393 | // If the current column is past the end of the next line, |
| 394 | // move to the end of the next line |
| 395 | const nextLineDisplayWidth = stringWidth(nextLine) |
| 396 | if (column > nextLineDisplayWidth) { |
| 397 | const newOffset = this.getOffset({ |
| 398 | line: line + 1, |
| 399 | column: nextLineDisplayWidth, |
| 400 | }) |
| 401 | return new Cursor(this.measuredText, newOffset, 0) |
| 402 | } |
| 403 | |
| 404 | // Otherwise, move to the same column on the next line |
| 405 | const newOffset = this.getOffset({ |
| 406 | line: line + 1, |
| 407 | column, |
| 408 | }) |
| 409 | return new Cursor(this.measuredText, newOffset, 0) |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Move to the start of the current line (column 0). |
no test coverage detected