Skip to content

Commit 64778d4

Browse files
fix: sync quicktools when tab switching
1 parent 57e8b1b commit 64778d4

2 files changed

Lines changed: 38 additions & 45 deletions

File tree

src/lib/applySettings.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@ import themes from "../theme/list";
55
import config from "./config";
66
import fonts from "./fonts";
77

8+
let listenerAdded = false;
9+
10+
function syncQuickToolsVisibility() {
11+
const { value: settings } = appSettings;
12+
const { $toggler } = quickTools;
13+
const activeFile = editorManager.activeFile;
14+
15+
if (settings.floatingButton && !activeFile?.hideQuickTools) {
16+
clearTimeout($toggler._hideTimeout);
17+
$toggler._hideTimeout = null;
18+
$toggler.classList.remove("hide");
19+
if (!$toggler.isConnected) {
20+
root.appendOuter($toggler);
21+
}
22+
} else {
23+
clearTimeout($toggler._hideTimeout);
24+
$toggler.classList.add("hide");
25+
$toggler._hideTimeout = setTimeout(() => {
26+
$toggler.remove();
27+
$toggler._hideTimeout = null;
28+
}, 300);
29+
}
30+
31+
if (activeFile?.hideQuickTools) {
32+
actions("set-height", { height: 0, save: false });
33+
} else {
34+
const quickToolsHeight =
35+
settings.quickTools !== undefined ? settings.quickTools : 1;
36+
actions("set-height", { height: quickToolsHeight, save: false });
37+
}
38+
}
39+
840
export default {
941
beforeRender() {
1042
//animation
@@ -30,24 +62,14 @@ export default {
3062
},
3163
afterRender() {
3264
const { value: settings } = appSettings;
33-
const { $toggler } = quickTools;
34-
if (settings.floatingButton && !editorManager.activeFile?.hideQuickTools) {
35-
clearTimeout($toggler._hideTimeout);
36-
$toggler._hideTimeout = null;
37-
$toggler.classList.remove("hide");
38-
if (!$toggler.isConnected) {
39-
root.appendOuter($toggler);
40-
}
41-
} else {
42-
clearTimeout($toggler._hideTimeout);
43-
$toggler.classList.add("hide");
44-
$toggler._hideTimeout = setTimeout(() => {
45-
$toggler.remove();
46-
$toggler._hideTimeout = null;
47-
}, 300);
65+
66+
if (!listenerAdded) {
67+
editorManager.on("switch-file", syncQuickToolsVisibility);
68+
listenerAdded = true;
4869
}
4970

50-
actions("set-height", settings.quickTools);
71+
syncQuickToolsVisibility();
72+
5173
fonts.setAppFont(settings.appFont);
5274
fonts.setEditorFont(settings.editorFont);
5375
if (!themes.applied) {

src/lib/editorFile.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import {
88
setScrollPosition,
99
} from "cm/editorUtils";
1010
import { getMode, getModeForPath } from "cm/modelist";
11-
import quickTools from "components/quickTools";
1211
import Sidebar from "components/sidebar";
1312
import tile from "components/tile";
1413
import toast from "components/toast";
1514
import confirm from "dialogs/confirm";
1615
import DOMPurify from "dompurify";
1716
import startDrag from "handlers/editorFileTab";
18-
import actions from "handlers/quickTools";
1917
import tag from "html-tag-js";
2018
import mimeTypes from "mime-types";
2119
import helpers from "utils/helpers";
@@ -1375,33 +1373,6 @@ export default class EditorFile {
13751373
this.#loadText();
13761374
}
13771375

1378-
// Handle quicktools visibility based on hideQuickTools property
1379-
if (this.hideQuickTools) {
1380-
const { $toggler } = quickTools;
1381-
clearTimeout($toggler._hideTimeout);
1382-
$toggler.classList.add("hide");
1383-
$toggler._hideTimeout = setTimeout(() => {
1384-
$toggler.remove();
1385-
$toggler._hideTimeout = null;
1386-
}, 300);
1387-
actions("set-height", { height: 0, save: false });
1388-
} else {
1389-
const { $toggler } = quickTools;
1390-
if (appSettings.value.floatingButton) {
1391-
clearTimeout($toggler._hideTimeout);
1392-
$toggler._hideTimeout = null;
1393-
$toggler.classList.remove("hide");
1394-
if (!$toggler.isConnected) {
1395-
root.appendOuter($toggler);
1396-
}
1397-
}
1398-
const quickToolsHeight =
1399-
appSettings.value.quickTools !== undefined
1400-
? appSettings.value.quickTools
1401-
: 1;
1402-
actions("set-height", { height: quickToolsHeight, save: false });
1403-
}
1404-
14051376
editorManager.header.subText = this.#getTitle();
14061377

14071378
this.#emit("focus", createFileEvent(this));

0 commit comments

Comments
 (0)