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