Commit dcd9a32
Translate selections when rows move in place (#616)
* Translate selections when lines are scrolled in place
A selection is anchored to absolute buffer rows. When a scroll pushes
lines into the scrollback that is safe: the rows stay valid and yDisp
advances. But when an application sets a scroll region that does not
start at the top of the screen (DECSTBM), Terminal.scroll shifts the
lines within the region instead, leaving yDisp untouched. The selection
anchors are then left pointing at whatever text scrolled into those rows,
so the highlight sits over the wrong text and copying returns it.
Full-screen TUIs hit this constantly: GitHub Copilot CLI, for example,
reserves its tab bar and prompt rows and scrolls the transcript between
them with ESC[4;34r followed by a linefeed, so any selection made while
output is streaming silently drifts onto other lines.
Selections now register with their terminal and are translated when lines
shift in place, and are cleared when they scroll out of the region.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Cover the remaining in-place row movements
Selections also need translating when rows move without going through the
scrollback on the other paths that shift lines in place:
- reverseIndex (ESC M) shifts rows down within the scroll region
- cmdInsertLines (CSI L) pushes rows below the cursor down
- cmdDeleteLines (CSI M) pulls rows below the cursor up
Margin mode (DECSLRM) shifts only the columns between the margins, and a
selection cannot be represented as partially shifted, so on those paths an
overlapping selection is cleared instead.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Complete selection translation for row scrolling
---------
Co-authored-by: David Collie <support@eyelock.net>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Miguel de Icaza <miguel@gnome.org>1 parent db838cc commit dcd9a32
3 files changed
Lines changed: 431 additions & 0 deletions
File tree
- Sources/SwiftTerm
- Tests/SwiftTermTests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
27 | 125 | | |
28 | 126 | | |
29 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
336 | 371 | | |
337 | 372 | | |
338 | 373 | | |
| |||
2525 | 2560 | | |
2526 | 2561 | | |
2527 | 2562 | | |
| 2563 | + | |
| 2564 | + | |
2528 | 2565 | | |
2529 | 2566 | | |
| 2567 | + | |
2530 | 2568 | | |
2531 | 2569 | | |
2532 | 2570 | | |
| |||
2536 | 2574 | | |
2537 | 2575 | | |
2538 | 2576 | | |
| 2577 | + | |
| 2578 | + | |
| 2579 | + | |
2539 | 2580 | | |
2540 | 2581 | | |
2541 | 2582 | | |
| |||
4765 | 4806 | | |
4766 | 4807 | | |
4767 | 4808 | | |
| 4809 | + | |
| 4810 | + | |
4768 | 4811 | | |
4769 | 4812 | | |
4770 | 4813 | | |
| |||
4773 | 4816 | | |
4774 | 4817 | | |
4775 | 4818 | | |
| 4819 | + | |
| 4820 | + | |
| 4821 | + | |
| 4822 | + | |
4776 | 4823 | | |
4777 | 4824 | | |
4778 | 4825 | | |
| |||
4801 | 4848 | | |
4802 | 4849 | | |
4803 | 4850 | | |
| 4851 | + | |
| 4852 | + | |
4804 | 4853 | | |
4805 | 4854 | | |
4806 | 4855 | | |
| |||
4809 | 4858 | | |
4810 | 4859 | | |
4811 | 4860 | | |
| 4861 | + | |
| 4862 | + | |
| 4863 | + | |
| 4864 | + | |
4812 | 4865 | | |
4813 | 4866 | | |
4814 | 4867 | | |
| |||
4872 | 4925 | | |
4873 | 4926 | | |
4874 | 4927 | | |
| 4928 | + | |
| 4929 | + | |
4875 | 4930 | | |
4876 | 4931 | | |
4877 | 4932 | | |
| |||
4883 | 4938 | | |
4884 | 4939 | | |
4885 | 4940 | | |
| 4941 | + | |
| 4942 | + | |
| 4943 | + | |
4886 | 4944 | | |
4887 | 4945 | | |
4888 | 4946 | | |
| |||
5351 | 5409 | | |
5352 | 5410 | | |
5353 | 5411 | | |
| 5412 | + | |
| 5413 | + | |
5354 | 5414 | | |
5355 | 5415 | | |
5356 | 5416 | | |
| |||
5381 | 5441 | | |
5382 | 5442 | | |
5383 | 5443 | | |
| 5444 | + | |
| 5445 | + | |
| 5446 | + | |
| 5447 | + | |
5384 | 5448 | | |
5385 | 5449 | | |
5386 | 5450 | | |
| |||
5405 | 5469 | | |
5406 | 5470 | | |
5407 | 5471 | | |
| 5472 | + | |
| 5473 | + | |
| 5474 | + | |
| 5475 | + | |
5408 | 5476 | | |
5409 | 5477 | | |
5410 | 5478 | | |
| |||
5844 | 5912 | | |
5845 | 5913 | | |
5846 | 5914 | | |
| 5915 | + | |
| 5916 | + | |
5847 | 5917 | | |
5848 | 5918 | | |
5849 | 5919 | | |
5850 | 5920 | | |
5851 | 5921 | | |
5852 | 5922 | | |
5853 | 5923 | | |
| 5924 | + | |
| 5925 | + | |
| 5926 | + | |
5854 | 5927 | | |
5855 | 5928 | | |
5856 | 5929 | | |
| |||
0 commit comments