()
| 350 | } |
| 351 | |
| 352 | down(): Cursor { |
| 353 | const { line, column } = this.getPosition() |
| 354 | if (line >= this.measuredText.lineCount - 1) { |
| 355 | return this |
| 356 | } |
| 357 | |
| 358 | // If there is no next line, stay on the current line, |
| 359 | // and let the caller handle it (e.g. for prompt input, |
| 360 | // we move to the next history entry) |
| 361 | const nextLine = this.measuredText.getWrappedText()[line + 1] |
| 362 | if (nextLine === undefined) { |
| 363 | return this |
| 364 | } |
| 365 | |
| 366 | // If the current column is past the end of the next line, |
| 367 | // move to the end of the next line |
| 368 | const nextLineDisplayWidth = stringWidth(nextLine) |
| 369 | if (column > nextLineDisplayWidth) { |
| 370 | const newOffset = this.getOffset({ |
| 371 | line: line + 1, |
| 372 | column: nextLineDisplayWidth, |
| 373 | }) |
| 374 | return new Cursor(this.measuredText, newOffset, 0) |
| 375 | } |
| 376 | |
| 377 | // Otherwise, move to the same column on the next line |
| 378 | const newOffset = this.getOffset({ |
| 379 | line: line + 1, |
| 380 | column, |
| 381 | }) |
| 382 | return new Cursor(this.measuredText, newOffset, 0) |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * Move to the start of the current line (column 0). |
no test coverage detected