@@ -128,7 +128,7 @@ export default class TerminalComponent {
128
128
let lastKnownScrollPosition = 0 ;
129
129
let isResizing = false ;
130
130
let resizeCount = 0 ;
131
- const RESIZE_DEBOUNCE = 150 ;
131
+ const RESIZE_DEBOUNCE = 100 ;
132
132
const MAX_RAPID_RESIZES = 3 ;
133
133
134
134
// Store original dimensions for comparison
@@ -170,8 +170,37 @@ export default class TerminalComponent {
170
170
await this . resizeTerminal ( size . cols , size . rows ) ;
171
171
}
172
172
173
- // Preserve scroll position for content-heavy terminals
174
- this . preserveViewportPosition ( lastKnownScrollPosition ) ;
173
+ // Handle keyboard resize cursor positioning
174
+ const heightRatio = size . rows / originalRows ;
175
+ if (
176
+ heightRatio < 0.75 &&
177
+ this . terminal . buffer &&
178
+ this . terminal . buffer . active
179
+ ) {
180
+ // Keyboard resize detected - ensure cursor is visible
181
+ const buffer = this . terminal . buffer . active ;
182
+ const cursorY = buffer . cursorY ;
183
+ const cursorViewportPos = buffer . baseY + cursorY ;
184
+ const viewportTop = buffer . viewportY ;
185
+ const viewportBottom = viewportTop + this . terminal . rows - 1 ;
186
+
187
+ if (
188
+ cursorViewportPos <= viewportTop + 1 ||
189
+ cursorViewportPos >= viewportBottom - 1
190
+ ) {
191
+ const targetScroll = Math . max (
192
+ 0 ,
193
+ Math . min (
194
+ buffer . length - this . terminal . rows ,
195
+ cursorViewportPos - Math . floor ( this . terminal . rows * 0.25 ) ,
196
+ ) ,
197
+ ) ;
198
+ this . terminal . scrollToLine ( targetScroll ) ;
199
+ }
200
+ } else {
201
+ // Regular resize - preserve scroll position
202
+ this . preserveViewportPosition ( lastKnownScrollPosition ) ;
203
+ }
175
204
176
205
// Update stored dimensions
177
206
originalRows = size . rows ;
@@ -437,7 +466,6 @@ export default class TerminalComponent {
437
466
height: 100%;
438
467
position: relative;
439
468
background: ${ this . options . theme . background } ;
440
- border-radius: 4px;
441
469
overflow: hidden;
442
470
` ;
443
471
@@ -455,6 +483,9 @@ export default class TerminalComponent {
455
483
456
484
this . container = container ;
457
485
486
+ // Apply terminal background color to container to match theme
487
+ this . container . style . background = this . options . theme . background ;
488
+
458
489
try {
459
490
try {
460
491
this . terminal . loadAddon ( this . webglAddon ) ;
@@ -675,6 +706,32 @@ export default class TerminalComponent {
675
706
* Focus terminal
676
707
*/
677
708
focus ( ) {
709
+ // Ensure cursor is visible before focusing to prevent half-visibility
710
+ if ( this . terminal . buffer && this . terminal . buffer . active ) {
711
+ const buffer = this . terminal . buffer . active ;
712
+ const cursorY = buffer . cursorY ;
713
+ const cursorViewportPos = buffer . baseY + cursorY ;
714
+ const viewportTop = buffer . viewportY ;
715
+ const viewportBottom = viewportTop + this . terminal . rows - 1 ;
716
+
717
+ // Check if cursor is fully visible (with margin to prevent half-visibility)
718
+ const isCursorFullyVisible =
719
+ cursorViewportPos >= viewportTop + 1 &&
720
+ cursorViewportPos <= viewportBottom - 2 ;
721
+
722
+ // If cursor is not fully visible, scroll to make it properly visible
723
+ if ( ! isCursorFullyVisible && buffer . length > this . terminal . rows ) {
724
+ const targetScroll = Math . max (
725
+ 0 ,
726
+ Math . min (
727
+ buffer . length - this . terminal . rows ,
728
+ cursorViewportPos - Math . floor ( this . terminal . rows * 0.25 ) ,
729
+ ) ,
730
+ ) ;
731
+ this . terminal . scrollToLine ( targetScroll ) ;
732
+ }
733
+ }
734
+
678
735
this . terminal . focus ( ) ;
679
736
}
680
737
0 commit comments