@@ -128,7 +128,7 @@ export default class TerminalComponent {
128128 let lastKnownScrollPosition = 0 ;
129129 let isResizing = false ;
130130 let resizeCount = 0 ;
131- const RESIZE_DEBOUNCE = 150 ;
131+ const RESIZE_DEBOUNCE = 100 ;
132132 const MAX_RAPID_RESIZES = 3 ;
133133
134134 // Store original dimensions for comparison
@@ -170,8 +170,37 @@ export default class TerminalComponent {
170170 await this . resizeTerminal ( size . cols , size . rows ) ;
171171 }
172172
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+ }
175204
176205 // Update stored dimensions
177206 originalRows = size . rows ;
@@ -437,7 +466,6 @@ export default class TerminalComponent {
437466 height: 100%;
438467 position: relative;
439468 background: ${ this . options . theme . background } ;
440- border-radius: 4px;
441469 overflow: hidden;
442470 ` ;
443471
@@ -455,6 +483,9 @@ export default class TerminalComponent {
455483
456484 this . container = container ;
457485
486+ // Apply terminal background color to container to match theme
487+ this . container . style . background = this . options . theme . background ;
488+
458489 try {
459490 try {
460491 this . terminal . loadAddon ( this . webglAddon ) ;
@@ -675,6 +706,32 @@ export default class TerminalComponent {
675706 * Focus terminal
676707 */
677708 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+
678735 this . terminal . focus ( ) ;
679736 }
680737
0 commit comments