-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
108 lines (95 loc) · 3.34 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const fileListContainer = document.getElementById("fileListContainer");
const toggleFileListButton = document.getElementById("toggleFileList");
const fileListContent = document.getElementById("fileListContent");
const contentDiv = document.getElementById("content");
const openFolderButton = document.getElementById("openFolder");
const opacitySlider = document.getElementById("opacitySlider");
const toggleThemeButton = document.getElementById("toggleTheme");
const zoomInButton = document.getElementById("zoomIn");
const zoomOutButton = document.getElementById("zoomOut");
const resetZoomButton = document.getElementById("resetZoom");
let zoomLevel = 1;
let isDarkTheme = true;
let isCollapsed = false;
let currentFolderPath = "";
let allFiles = [];
// Function to apply zoom
function applyZoom() {
const fontSize = `${zoomLevel * 16}px`; // Base font size is 16px
contentDiv.style.fontSize = fontSize; // Dynamically adjust font size
}
// Zoom in
zoomInButton.addEventListener("click", () => {
zoomLevel += 0.1; // Increment zoom level
applyZoom();
});
// Zoom out
zoomOutButton.addEventListener("click", () => {
if (zoomLevel > 0.5) {
// Prevent zooming out too far
zoomLevel -= 0.1; // Decrement zoom level
applyZoom();
}
});
// Reset zoom
resetZoomButton.addEventListener("click", () => {
zoomLevel = 1; // Reset to default zoom level
applyZoom();
});
// Function to switch themes
toggleThemeButton.addEventListener("click", () => {
const themeLink = document.querySelector('link[rel="stylesheet"]');
if (isDarkTheme) {
themeLink.href = "./styles/github.css";
toggleThemeButton.textContent = "☀️";
isDarkTheme = false;
} else {
themeLink.href = "./styles/github-dark.css";
toggleThemeButton.textContent = "🌙";
isDarkTheme = true;
}
});
// Handle collapse/expand
toggleFileListButton.addEventListener("click", () => {
if (isCollapsed) {
fileListContainer.style.width = "30%";
toggleFileListButton.textContent = "<";
} else {
fileListContainer.style.width = "0";
toggleFileListButton.textContent = ">";
}
isCollapsed = !isCollapsed;
});
// Load the files and populate the list
openFolderButton.addEventListener("click", async () => {
currentFolderPath = await window.api.selectDirectory();
allFiles = await window.api.readFiles(currentFolderPath);
displayFiles(allFiles);
});
function displayFiles(files) {
fileListContent.innerHTML = files.map((file) => `<li>${file}</li>`).join("");
}
// Add event listener to the filter input
const filterInput = document.getElementById("filterInput");
filterInput.addEventListener("input", (e) => {
const filterText = e.target.value.toLowerCase();
const filteredFiles = allFiles.filter((file) =>
file.toLowerCase().includes(filterText)
);
displayFiles(filteredFiles);
});
// Handle file click
fileListContent.addEventListener("click", async (e) => {
if (e.target.tagName === "LI") {
const filePath = `${currentFolderPath}/${e.target.textContent}`;
const content = await window.api.readFile(filePath);
const renderedContent = window.api.renderMarkdown(content);
contentDiv.innerHTML = renderedContent;
window.api.highlightCode();
}
});
// Handle opacity change
opacitySlider.addEventListener("input", (e) => {
const opacity = parseFloat(e.target.value);
window.api.setOpacity(opacity); // Use API exposed via preload.js
});