Skip to content

Commit c7d29e8

Browse files
committed
fix: update terminal container background when theme changes
- Apply terminal background color to container on mount - Update container background when terminal theme changes in settings
1 parent 9aedda7 commit c7d29e8

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

src/components/terminal/terminal.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,28 @@ export default class TerminalComponent {
172172

173173
// Handle keyboard resize cursor positioning
174174
const heightRatio = size.rows / originalRows;
175-
if (heightRatio < 0.75 && this.terminal.buffer && this.terminal.buffer.active) {
175+
if (
176+
heightRatio < 0.75 &&
177+
this.terminal.buffer &&
178+
this.terminal.buffer.active
179+
) {
176180
// Keyboard resize detected - ensure cursor is visible
177181
const buffer = this.terminal.buffer.active;
178182
const cursorY = buffer.cursorY;
179183
const cursorViewportPos = buffer.baseY + cursorY;
180184
const viewportTop = buffer.viewportY;
181185
const viewportBottom = viewportTop + this.terminal.rows - 1;
182-
183-
if (cursorViewportPos <= viewportTop + 1 || cursorViewportPos >= viewportBottom - 1) {
184-
const targetScroll = Math.max(0,
185-
Math.min(buffer.length - this.terminal.rows,
186-
cursorViewportPos - Math.floor(this.terminal.rows * 0.25)
187-
)
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+
),
188197
);
189198
this.terminal.scrollToLine(targetScroll);
190199
}
@@ -474,6 +483,9 @@ export default class TerminalComponent {
474483

475484
this.container = container;
476485

486+
// Apply terminal background color to container to match theme
487+
this.container.style.background = this.options.theme.background;
488+
477489
try {
478490
try {
479491
this.terminal.loadAddon(this.webglAddon);
@@ -701,16 +713,20 @@ export default class TerminalComponent {
701713
const cursorViewportPos = buffer.baseY + cursorY;
702714
const viewportTop = buffer.viewportY;
703715
const viewportBottom = viewportTop + this.terminal.rows - 1;
704-
716+
705717
// Check if cursor is fully visible (with margin to prevent half-visibility)
706-
const isCursorFullyVisible = cursorViewportPos >= viewportTop + 1 && cursorViewportPos <= viewportBottom - 2;
718+
const isCursorFullyVisible =
719+
cursorViewportPos >= viewportTop + 1 &&
720+
cursorViewportPos <= viewportBottom - 2;
707721

708722
// If cursor is not fully visible, scroll to make it properly visible
709723
if (!isCursorFullyVisible && buffer.length > this.terminal.rows) {
710-
const targetScroll = Math.max(0,
711-
Math.min(buffer.length - this.terminal.rows,
712-
cursorViewportPos - Math.floor(this.terminal.rows * 0.25)
713-
)
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+
),
714730
);
715731
this.terminal.scrollToLine(targetScroll);
716732
}

src/components/terminal/terminalTouchSelection.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,11 @@ export default class TerminalTouchSelection {
277277
const horizontalDelta = touch.clientX - this.touchStartPos.x;
278278

279279
// Check if this looks like a back gesture (started near edge and moving horizontally inward)
280-
if (this.isEdgeGesture(this.initialTouchPos) &&
281-
Math.abs(horizontalDelta) > deltaY &&
282-
deltaX > this.options.moveThreshold) {
280+
if (
281+
this.isEdgeGesture(this.initialTouchPos) &&
282+
Math.abs(horizontalDelta) > deltaY &&
283+
deltaX > this.options.moveThreshold
284+
) {
283285
// This looks like a back gesture, cancel selection
284286
if (this.tapHoldTimeout) {
285287
clearTimeout(this.tapHoldTimeout);
@@ -1165,17 +1167,17 @@ export default class TerminalTouchSelection {
11651167
isEdgeGesture(touch) {
11661168
const edgeThreshold = 30; // pixels from screen edge
11671169
const screenWidth = window.innerWidth;
1168-
1170+
11691171
// Check if touch starts near left edge (most common for back gesture)
11701172
if (touch.clientX <= edgeThreshold) {
11711173
return true;
11721174
}
1173-
1175+
11741176
// Check if touch starts near right edge (for RTL languages or right-handed back gesture)
11751177
if (touch.clientX >= screenWidth - edgeThreshold) {
11761178
return true;
11771179
}
1178-
1180+
11791181
return false;
11801182
}
11811183

src/settings/terminalSettings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,11 @@ async function updateActiveTerminals(key, value) {
372372
case "theme":
373373
tab.terminalComponent.terminal.options.theme =
374374
TerminalThemeManager.getTheme(value);
375+
// Update container background to match new theme
376+
if (tab.terminalComponent.container) {
377+
tab.terminalComponent.container.style.background =
378+
tab.terminalComponent.terminal.options.theme.background;
379+
}
375380
break;
376381
case "imageSupport":
377382
tab.terminalComponent.updateImageSupport(value);

0 commit comments

Comments
 (0)