TestPageKeysMoveCursorByHeight: PgUp/PgDn move the cursor by one prompt-height. bubbles/textarea ships an empty viewport keymap, so without our handling these keys are no-ops (mouse wheel already scrolls via the MouseMsg path).
(t *testing.T)
| 371 | // bubbles/textarea ships an empty viewport keymap, so without our handling |
| 372 | // these keys are no-ops (mouse wheel already scrolls via the MouseMsg path). |
| 373 | func TestPageKeysMoveCursorByHeight(t *testing.T) { |
| 374 | p := newChippablePrompt() |
| 375 | // Fill with many rows. SetValue installs all at once, avoiding the chip |
| 376 | // threshold and per-line typing. |
| 377 | var b strings.Builder |
| 378 | for i := 0; i < 40; i++ { |
| 379 | fmt.Fprintf(&b, "row%02d\n", i) |
| 380 | } |
| 381 | p.SetValue(b.String()) |
| 382 | p.CursorEnd() |
| 383 | startRow := p.ta.Line() |
| 384 | if startRow < 10 { |
| 385 | t.Fatalf("precondition: cursor should be deep into the content, got row %d", startRow) |
| 386 | } |
| 387 | |
| 388 | // PgUp moves the cursor up; repositionView scrolls the viewport with it. |
| 389 | p, _ = p.Update(tea.KeyMsg{Type: tea.KeyPgUp}) |
| 390 | if p.ta.Line() >= startRow { |
| 391 | t.Fatalf("PgUp should move cursor up from row %d, ended at %d", |
| 392 | startRow, p.ta.Line()) |
| 393 | } |
| 394 | |
| 395 | upRow := p.ta.Line() |
| 396 | p, _ = p.Update(tea.KeyMsg{Type: tea.KeyPgDown}) |
| 397 | if p.ta.Line() <= upRow { |
| 398 | t.Fatalf("PgDn should move cursor down from row %d, ended at %d", |
| 399 | upRow, p.ta.Line()) |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | // TestCarriageReturnLineEndings: lone-\r separators (old-mac-style, some VS Code |
| 404 | // TERM setups) must still yield a correct chip line count. bubbles/textarea |