MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / closeTabs

Function closeTabs

src/lib/commands.js:80–124  ·  view source on GitHub ↗
(files, options = {})

Source from the content-addressed store, hash-verified

78}
79
80async function closeTabs(files, options = {}) {
81 const closableFiles = files.filter((file) => file && !file.pinned);
82 if (!closableFiles.length) return false;
83
84 const {
85 unsavedWarning = strings["unsaved files warning"],
86 saveLabel = strings["save all"],
87 closeLabel = strings["close all"],
88 saveWarning = strings["save all warning"],
89 closeWarning = strings["close all warning"],
90 } = options;
91
92 let save = false;
93 const unsavedFiles = closableFiles.filter((file) => file.isUnsaved).length;
94 if (unsavedFiles) {
95 const confirmation = await confirm(strings["warning"], unsavedWarning);
96 if (!confirmation) return false;
97
98 const option = await select(strings["select"], [
99 ["save", saveLabel],
100 ["close", closeLabel],
101 ["cancel", strings["cancel"]],
102 ]);
103 if (option === "cancel") return false;
104
105 if (option === "save") {
106 const doSave = await confirm(strings["warning"], saveWarning);
107 if (!doSave) return false;
108 save = true;
109 } else {
110 const doClose = await confirm(strings["warning"], closeWarning);
111 if (!doClose) return false;
112 }
113 }
114
115 for (const file of [...closableFiles]) {
116 if (save) {
117 await file.save();
118 }
119
120 await file.remove(true, { silentPinned: true });
121 }
122
123 return true;
124}
125
126export default {
127 async "run-tests"() {

Callers 4

"close-all-tabs"Function · 0.85
"close-tabs-to-left"Function · 0.85
"close-tabs-to-right"Function · 0.85
"close-other-tabs"Function · 0.85

Calls 4

confirmFunction · 0.85
saveMethod · 0.80
selectFunction · 0.70
removeMethod · 0.45

Tested by

no test coverage detected