Skip to content

Commit 9307c38

Browse files
committed
Add confirmation prompt before closing terminal tabs
Introduces a new setting 'confirmTabClose' to prompt users for confirmation before closing terminal tabs. The setting is added to the default terminal settings and terminal settings UI, and the terminal manager now checks this setting before closing a terminal tab.
1 parent 6c8ab56 commit 9307c38

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/components/terminal/terminalDefaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const DEFAULT_TERMINAL_SETTINGS = {
1414
letterSpacing: 0,
1515
imageSupport: false,
1616
fontLigatures: false,
17+
confirmTabClose: true,
1718
// Touch selection settings
1819
touchSelectionTapHoldDuration: 600,
1920
touchSelectionMoveThreshold: 8,

src/components/terminal/terminalManager.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import EditorFile from "lib/editorFile";
77
import TerminalComponent from "./terminal";
88
import "@xterm/xterm/css/xterm.css";
99
import toast from "components/toast";
10+
import confirm from "dialogs/confirm";
11+
import appSettings from "lib/settings";
1012
import helpers from "utils/helpers";
1113

1214
const TERMINAL_SESSION_STORAGE_KEY = "acodeTerminalSessions";
@@ -413,6 +415,22 @@ class TerminalManager {
413415
this.closeTerminal(terminalId);
414416
};
415417

418+
terminalFile._skipTerminalCloseConfirm = false;
419+
const originalRemove = terminalFile.remove.bind(terminalFile);
420+
terminalFile.remove = async (force = false) => {
421+
if (
422+
!terminalFile._skipTerminalCloseConfirm &&
423+
this.shouldConfirmTerminalClose()
424+
) {
425+
const message = `${strings["close"]} ${strings["terminal"]}?`;
426+
const shouldClose = await confirm(strings["confirm"], message);
427+
if (!shouldClose) return;
428+
}
429+
430+
terminalFile._skipTerminalCloseConfirm = false;
431+
return originalRemove(force);
432+
};
433+
416434
// Enhanced resize handling with debouncing
417435
let resizeTimeout = null;
418436
const RESIZE_DEBOUNCE = 200;
@@ -519,6 +537,7 @@ class TerminalManager {
519537
}
520538

521539
this.closeTerminal(terminalId);
540+
terminalFile._skipTerminalCloseConfirm = true;
522541
terminalFile.remove(true);
523542
toast(message);
524543
};
@@ -731,6 +750,14 @@ class TerminalManager {
731750
}
732751
});
733752
}
753+
754+
shouldConfirmTerminalClose() {
755+
const settings = appSettings?.value?.terminalSettings;
756+
if (settings && settings.confirmTabClose === false) {
757+
return false;
758+
}
759+
return true;
760+
}
734761
}
735762

736763
// Create singleton instance

src/settings/terminalSettings.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ export default function terminalSettings() {
165165
checkbox: terminalValues.fontLigatures,
166166
info: "Whether font ligatures are enabled in the terminal.",
167167
},
168+
{
169+
key: "confirmTabClose",
170+
text: `${strings["confirm"]} ${strings["terminal"]} tab close`,
171+
checkbox: terminalValues.confirmTabClose !== false,
172+
info: "Ask for confirmation before closing terminal tabs.",
173+
},
168174
{
169175
key: "backup",
170176
text: strings.backup.capitalize(),

0 commit comments

Comments
 (0)