gh-here 3.0.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +0 -0
- package/.playwright-mcp/fixed-alignment.png +0 -0
- package/.playwright-mcp/fixed-layout.png +0 -0
- package/.playwright-mcp/gh-here-home-header-table.png +0 -0
- package/.playwright-mcp/gh-here-home.png +0 -0
- package/.playwright-mcp/line-selection-multiline.png +0 -0
- package/.playwright-mcp/line-selection-test-after.png +0 -0
- package/.playwright-mcp/line-selection-test-before.png +0 -0
- package/.playwright-mcp/page-2026-01-03T17-58-21-336Z.png +0 -0
- package/lib/constants.js +25 -15
- package/lib/content-search.js +212 -0
- package/lib/error-handler.js +39 -28
- package/lib/file-utils.js +438 -287
- package/lib/git.js +10 -54
- package/lib/gitignore.js +70 -41
- package/lib/renderers.js +15 -19
- package/lib/server.js +70 -193
- package/lib/symbol-parser.js +600 -0
- package/package.json +1 -1
- package/public/app.js +134 -68
- package/public/js/constants.js +50 -34
- package/public/js/content-search-handler.js +551 -0
- package/public/js/file-viewer.js +437 -0
- package/public/js/focus-mode.js +280 -0
- package/public/js/inline-search.js +659 -0
- package/public/js/modal-manager.js +14 -28
- package/public/js/symbol-outline.js +454 -0
- package/public/js/utils.js +152 -94
- package/public/styles.css +2049 -296
- package/.claude/settings.local.json +0 -30
- package/SAMPLE.md +0 -287
- package/lib/validation.js +0 -77
- package/public/app.js.backup +0 -1902
- package/public/js/draft-manager.js +0 -36
- package/public/js/editor-manager.js +0 -159
- package/test.js +0 -138
- package/tests/draftManager.test.js +0 -241
- package/tests/fileTypeDetection.test.js +0 -111
- package/tests/httpService.test.js +0 -268
- package/tests/languageDetection.test.js +0 -145
- package/tests/pathUtils.test.js +0 -136
package/public/app.js.backup
DELETED
|
@@ -1,1902 +0,0 @@
|
|
|
1
|
-
// Octicons directly embedded for frontend use
|
|
2
|
-
const octicons = {
|
|
3
|
-
'file-directory': '<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-file-directory" aria-hidden="true"><path d="M0 2.75C0 1.784.784 1 1.75 1H5c.55 0 1.07.26 1.4.7l.9 1.2a.25.25 0 0 0 .2.1h6.75c.966 0 1.75.784 1.75 1.75v8.5A1.75 1.75 0 0 1 14.25 15H1.75A1.75 1.75 0 0 1 0 13.25Zm1.75-.25a.25.25 0 0 0-.25.25v10.5c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25v-8.5a.25.25 0 0 0-.25-.25H7.5c-.55 0-1.07-.26-1.4-.7l-.9-1.2a.25.25 0 0 0-.2-.1Z"></path></svg>',
|
|
4
|
-
'git-commit': '<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-git-commit" aria-hidden="true"><path d="M11.93 8.5a4.002 4.002 0 0 1-7.86 0H.75a.75.75 0 0 1 0-1.5h3.32a4.002 4.002 0 0 1 7.86 0h3.32a.75.75 0 0 1 0 1.5Zm-1.43-.75a2.5 2.5 0 1 0-5 0 2.5 2.5 0 0 0 5 0Z"></path></svg>',
|
|
5
|
-
'diff': '<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-diff" aria-hidden="true"><path d="M8.75 1.75V5H12a.75.75 0 0 1 0 1.5H8.75v3.25a.75.75 0 0 1-1.5 0V6.5H4A.75.75 0 0 1 4 5h3.25V1.75a.75.75 0 0 1 1.5 0ZM4 13h8a.75.75 0 0 1 0 1.5H4A.75.75 0 0 1 4 13Z"></path></svg>',
|
|
6
|
-
'copy': '<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-copy" aria-hidden="true"><path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z"></path><path d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"></path></svg>',
|
|
7
|
-
'download': '<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-download" aria-hidden="true"><path d="M2.75 14A1.75 1.75 0 0 1 1 12.25v-2.5a.75.75 0 0 1 1.5 0v2.5c0 .138.112.25.25.25h10.5a.25.25 0 0 0 .25-.25v-2.5a.75.75 0 0 1 1.5 0v2.5A1.75 1.75 0 0 1 13.25 14Z"></path><path d="M7.25 7.689V2a.75.75 0 0 1 1.5 0v5.689l1.97-1.969a.749.749 0 1 1 1.06 1.06l-3.25 3.25a.749.749 0 0 1-1.06 0L4.22 6.78a.749.749 0 1 1 1.06-1.06l1.97 1.969Z"></path></svg>',
|
|
8
|
-
'pencil': '<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-pencil" aria-hidden="true"><path d="M11.013 1.427a1.75 1.75 0 0 1 2.474 0l1.086 1.086a1.75 1.75 0 0 1 0 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 0 1-.927-.928l.929-3.25c.081-.286.235-.547.445-.758l8.61-8.61Zm.176 4.823L9.75 4.81l-6.286 6.287a.253.253 0 0 0-.064.108l-.558 1.953 1.953-.558a.253.253 0 0 0 .108-.064Zm1.238-3.763a.25.25 0 0 0-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 0 0 0-.354Z"></path></svg>',
|
|
9
|
-
'x': '<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-x" aria-hidden="true"><path d="M3.72 3.72a.75.75 0 0 1 1.06 0L8 6.94l3.22-3.22a.749.749 0 0 1 1.275.326.749.749 0 0 1-.215.734L9.06 8l3.22 3.22a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L8 9.06l-3.22 3.22a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042L6.94 8 3.72 4.78a.75.75 0 0 1 0-1.06Z"></path></svg>',
|
|
10
|
-
'check': '<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-check" aria-hidden="true"><path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"></path></svg>',
|
|
11
|
-
|
|
12
|
-
// Helper to get an icon with optional classes
|
|
13
|
-
get(name, options = {}) {
|
|
14
|
-
const svg = this[name];
|
|
15
|
-
if (!svg) return `<span class="missing-icon">[${name}]</span>`;
|
|
16
|
-
|
|
17
|
-
if (options.class) {
|
|
18
|
-
return svg.replace('class="octicon', `class="${options.class} octicon`);
|
|
19
|
-
}
|
|
20
|
-
return svg;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// Language detection utility - pure function, easily testable
|
|
25
|
-
function getLanguageFromExtension(filename) {
|
|
26
|
-
const ext = filename.split('.').pop().toLowerCase();
|
|
27
|
-
const languageMap = {
|
|
28
|
-
// JavaScript family
|
|
29
|
-
'js': 'javascript',
|
|
30
|
-
'mjs': 'javascript',
|
|
31
|
-
'jsx': 'javascript',
|
|
32
|
-
'ts': 'typescript',
|
|
33
|
-
'tsx': 'typescript',
|
|
34
|
-
|
|
35
|
-
// Web languages
|
|
36
|
-
'html': 'html',
|
|
37
|
-
'htm': 'html',
|
|
38
|
-
'css': 'css',
|
|
39
|
-
'scss': 'scss',
|
|
40
|
-
'sass': 'sass',
|
|
41
|
-
'less': 'less',
|
|
42
|
-
|
|
43
|
-
// Data formats
|
|
44
|
-
'json': 'json',
|
|
45
|
-
'xml': 'xml',
|
|
46
|
-
'yaml': 'yaml',
|
|
47
|
-
'yml': 'yaml',
|
|
48
|
-
|
|
49
|
-
// Programming languages
|
|
50
|
-
'py': 'python',
|
|
51
|
-
'java': 'java',
|
|
52
|
-
'go': 'go',
|
|
53
|
-
'rs': 'rust',
|
|
54
|
-
'php': 'php',
|
|
55
|
-
'rb': 'ruby',
|
|
56
|
-
'swift': 'swift',
|
|
57
|
-
'kt': 'kotlin',
|
|
58
|
-
'dart': 'dart',
|
|
59
|
-
|
|
60
|
-
// Systems languages
|
|
61
|
-
'c': 'c',
|
|
62
|
-
'cpp': 'cpp',
|
|
63
|
-
'cc': 'cpp',
|
|
64
|
-
'cxx': 'cpp',
|
|
65
|
-
'h': 'c',
|
|
66
|
-
'hpp': 'cpp',
|
|
67
|
-
|
|
68
|
-
// Shell and scripts
|
|
69
|
-
'sh': 'shell',
|
|
70
|
-
'bash': 'shell',
|
|
71
|
-
'zsh': 'shell',
|
|
72
|
-
'fish': 'shell',
|
|
73
|
-
'ps1': 'powershell',
|
|
74
|
-
|
|
75
|
-
// Other languages
|
|
76
|
-
'sql': 'sql',
|
|
77
|
-
'r': 'r',
|
|
78
|
-
'scala': 'scala',
|
|
79
|
-
'clj': 'clojure',
|
|
80
|
-
'lua': 'lua',
|
|
81
|
-
'pl': 'perl',
|
|
82
|
-
'groovy': 'groovy',
|
|
83
|
-
|
|
84
|
-
// Config and text
|
|
85
|
-
'md': 'markdown',
|
|
86
|
-
'txt': 'plaintext',
|
|
87
|
-
'log': 'plaintext'
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// Special filename handling
|
|
91
|
-
const basename = filename.toLowerCase();
|
|
92
|
-
if (basename === 'dockerfile' || basename.startsWith('dockerfile.')) return 'dockerfile';
|
|
93
|
-
if (basename === 'makefile') return 'makefile';
|
|
94
|
-
if (basename.startsWith('.env')) return 'dotenv';
|
|
95
|
-
if (basename === 'package.json' || basename === 'composer.json') return 'json';
|
|
96
|
-
|
|
97
|
-
return languageMap[ext] || 'plaintext';
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Draft management utilities - pure functions, easily testable
|
|
101
|
-
const DraftManager = {
|
|
102
|
-
STORAGE_PREFIX: 'gh-here-draft-',
|
|
103
|
-
|
|
104
|
-
saveDraft(filePath, content) {
|
|
105
|
-
localStorage.setItem(`${this.STORAGE_PREFIX}${filePath}`, content);
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
loadDraft(filePath) {
|
|
109
|
-
return localStorage.getItem(`${this.STORAGE_PREFIX}${filePath}`);
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
clearDraft(filePath) {
|
|
113
|
-
localStorage.removeItem(`${this.STORAGE_PREFIX}${filePath}`);
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
// Helper to check if draft exists and differs from content
|
|
117
|
-
hasDraftChanges(filePath, originalContent) {
|
|
118
|
-
const draft = this.loadDraft(filePath);
|
|
119
|
-
return draft !== null && draft !== originalContent;
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
// Get all draft keys for cleanup/debugging
|
|
123
|
-
getAllDrafts() {
|
|
124
|
-
const drafts = {};
|
|
125
|
-
for (let i = 0; i < localStorage.length; i++) {
|
|
126
|
-
const key = localStorage.key(i);
|
|
127
|
-
if (key.startsWith(this.STORAGE_PREFIX)) {
|
|
128
|
-
const filePath = key.replace(this.STORAGE_PREFIX, '');
|
|
129
|
-
drafts[filePath] = localStorage.getItem(key);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return drafts;
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// Path utility functions - pure functions, easily testable
|
|
137
|
-
const PathUtils = {
|
|
138
|
-
// Extract current path from URL parameters
|
|
139
|
-
getCurrentPath() {
|
|
140
|
-
const currentUrl = new URL(window.location.href);
|
|
141
|
-
return currentUrl.searchParams.get('path') || '';
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
// Navigate to parent directory
|
|
145
|
-
getParentPath(currentPath) {
|
|
146
|
-
if (!currentPath || currentPath === '') {
|
|
147
|
-
return null; // Already at root
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const pathParts = currentPath.split('/').filter(p => p);
|
|
151
|
-
if (pathParts.length === 0) {
|
|
152
|
-
return null; // Already at root
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
pathParts.pop();
|
|
156
|
-
return pathParts.join('/');
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
// Build file path from directory and filename
|
|
160
|
-
buildFilePath(currentPath, filename) {
|
|
161
|
-
return currentPath ? `${currentPath}/${filename}` : filename;
|
|
162
|
-
},
|
|
163
|
-
|
|
164
|
-
// Get filename from full path
|
|
165
|
-
getFileName(filePath) {
|
|
166
|
-
return filePath.split('/').pop() || 'file.txt';
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
// Build URL with encoded path parameter
|
|
170
|
-
buildPathUrl(basePath, targetPath) {
|
|
171
|
-
return targetPath ? `${basePath}?path=${encodeURIComponent(targetPath)}` : basePath;
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
// Extract directory path from file path
|
|
175
|
-
getDirectoryPath(filePath) {
|
|
176
|
-
const parts = filePath.split('/').filter(p => p);
|
|
177
|
-
if (parts.length <= 1) return '';
|
|
178
|
-
return parts.slice(0, -1).join('/');
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
// Notification system - global scope for access from commit functions
|
|
183
|
-
function showNotification(message, type = 'info') {
|
|
184
|
-
// Remove existing notifications
|
|
185
|
-
const existingNotifications = document.querySelectorAll('.notification');
|
|
186
|
-
existingNotifications.forEach(n => n.remove());
|
|
187
|
-
|
|
188
|
-
const notification = document.createElement('div');
|
|
189
|
-
notification.className = `notification notification-${type}`;
|
|
190
|
-
notification.textContent = message;
|
|
191
|
-
|
|
192
|
-
document.body.appendChild(notification);
|
|
193
|
-
|
|
194
|
-
// Auto-remove after 4 seconds
|
|
195
|
-
setTimeout(() => {
|
|
196
|
-
if (notification.parentNode) {
|
|
197
|
-
notification.style.opacity = '0';
|
|
198
|
-
setTimeout(() => notification.remove(), 300);
|
|
199
|
-
}
|
|
200
|
-
}, 4000);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
document.addEventListener('DOMContentLoaded', function() {
|
|
204
|
-
|
|
205
|
-
const themeToggle = document.getElementById('theme-toggle');
|
|
206
|
-
const html = document.documentElement;
|
|
207
|
-
const searchInput = document.getElementById('file-search');
|
|
208
|
-
const fileTable = document.getElementById('file-table');
|
|
209
|
-
const searchHotkey = document.querySelector('.search-hotkey');
|
|
210
|
-
|
|
211
|
-
let currentFocusIndex = -1;
|
|
212
|
-
let fileRows = [];
|
|
213
|
-
|
|
214
|
-
// Removed loading state utilities - not needed for local operations
|
|
215
|
-
|
|
216
|
-
// Monaco Editor integration
|
|
217
|
-
let monacoFileEditor = null;
|
|
218
|
-
let monacoNewFileEditor = null;
|
|
219
|
-
|
|
220
|
-
// Note: getLanguageFromExtension is now a global utility function
|
|
221
|
-
|
|
222
|
-
// Initialize Monaco Editor
|
|
223
|
-
function initializeMonaco() {
|
|
224
|
-
if (typeof require !== 'undefined') {
|
|
225
|
-
require.config({ paths: { 'vs': 'https://unpkg.com/monaco-editor@0.45.0/min/vs' }});
|
|
226
|
-
|
|
227
|
-
require(['vs/editor/editor.main'], function () {
|
|
228
|
-
// Configure Monaco Editor to work without web workers (avoids CORS issues)
|
|
229
|
-
self.MonacoEnvironment = {
|
|
230
|
-
getWorker: function(workerId, label) {
|
|
231
|
-
// Return undefined to disable workers and use main thread processing
|
|
232
|
-
// This avoids CORS issues with unpkg CDN while still providing syntax highlighting
|
|
233
|
-
return undefined;
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
// Set Monaco theme based on current theme
|
|
238
|
-
const currentTheme = html.getAttribute('data-theme');
|
|
239
|
-
const monacoTheme = currentTheme === 'dark' ? 'vs-dark' : 'vs';
|
|
240
|
-
monaco.editor.setTheme(monacoTheme);
|
|
241
|
-
|
|
242
|
-
// Initialize new file editor if container exists
|
|
243
|
-
const newFileEditorContainer = document.getElementById('new-file-content');
|
|
244
|
-
if (newFileEditorContainer) {
|
|
245
|
-
monacoNewFileEditor = monaco.editor.create(newFileEditorContainer, {
|
|
246
|
-
value: '',
|
|
247
|
-
language: 'plaintext',
|
|
248
|
-
theme: monacoTheme,
|
|
249
|
-
minimap: { enabled: false },
|
|
250
|
-
lineNumbers: 'on',
|
|
251
|
-
wordWrap: 'off',
|
|
252
|
-
scrollBeyondLastLine: false,
|
|
253
|
-
fontSize: 12,
|
|
254
|
-
lineHeight: 20, // Match view mode breathing
|
|
255
|
-
fontFamily: "'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace",
|
|
256
|
-
padding: { top: 20, bottom: 20, left: 20, right: 20 },
|
|
257
|
-
renderLineHighlight: 'line',
|
|
258
|
-
selectOnLineNumbers: true,
|
|
259
|
-
automaticLayout: true,
|
|
260
|
-
folding: true,
|
|
261
|
-
foldingHighlight: true,
|
|
262
|
-
foldingStrategy: 'auto',
|
|
263
|
-
showFoldingControls: 'mouseover',
|
|
264
|
-
bracketPairColorization: { enabled: true },
|
|
265
|
-
guides: {
|
|
266
|
-
bracketPairs: true,
|
|
267
|
-
indentation: true
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// Set global flag that Monaco is ready
|
|
273
|
-
window.monacoReady = true;
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// Initialize Monaco when DOM is ready
|
|
279
|
-
if (document.readyState === 'loading') {
|
|
280
|
-
document.addEventListener('DOMContentLoaded', initializeMonaco);
|
|
281
|
-
} else {
|
|
282
|
-
initializeMonaco();
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// Initialize
|
|
286
|
-
updateFileRows();
|
|
287
|
-
|
|
288
|
-
// Detect system theme preference
|
|
289
|
-
const systemPrefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
290
|
-
const systemTheme = systemPrefersDark ? 'dark' : 'light';
|
|
291
|
-
|
|
292
|
-
// Load saved theme or default to system preference
|
|
293
|
-
const savedTheme = localStorage.getItem('gh-here-theme') || systemTheme;
|
|
294
|
-
html.setAttribute('data-theme', savedTheme);
|
|
295
|
-
updateThemeIcon(savedTheme);
|
|
296
|
-
|
|
297
|
-
// Listen for system theme changes (only if no manual override is saved)
|
|
298
|
-
if (window.matchMedia) {
|
|
299
|
-
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
300
|
-
mediaQuery.addListener(function(e) {
|
|
301
|
-
// Only auto-update if user hasn't manually set a theme
|
|
302
|
-
if (!localStorage.getItem('gh-here-theme')) {
|
|
303
|
-
const newTheme = e.matches ? 'dark' : 'light';
|
|
304
|
-
html.setAttribute('data-theme', newTheme);
|
|
305
|
-
updateThemeIcon(newTheme);
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// Theme toggle functionality
|
|
311
|
-
themeToggle.addEventListener('click', function() {
|
|
312
|
-
const currentTheme = html.getAttribute('data-theme');
|
|
313
|
-
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
|
|
314
|
-
|
|
315
|
-
html.setAttribute('data-theme', newTheme);
|
|
316
|
-
localStorage.setItem('gh-here-theme', newTheme);
|
|
317
|
-
updateThemeIcon(newTheme);
|
|
318
|
-
|
|
319
|
-
// Update Monaco editor themes
|
|
320
|
-
if (typeof monaco !== 'undefined') {
|
|
321
|
-
const monacoTheme = newTheme === 'dark' ? 'vs-dark' : 'vs';
|
|
322
|
-
monaco.editor.setTheme(monacoTheme);
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
// Gitignore toggle functionality
|
|
327
|
-
const gitignoreToggle = document.getElementById('gitignore-toggle');
|
|
328
|
-
if (gitignoreToggle) {
|
|
329
|
-
gitignoreToggle.addEventListener('click', function() {
|
|
330
|
-
const currentUrl = new URL(window.location.href);
|
|
331
|
-
const currentGitignoreState = currentUrl.searchParams.get('gitignore');
|
|
332
|
-
const newGitignoreState = currentGitignoreState === 'false' ? null : 'false';
|
|
333
|
-
|
|
334
|
-
if (newGitignoreState) {
|
|
335
|
-
currentUrl.searchParams.set('gitignore', newGitignoreState);
|
|
336
|
-
} else {
|
|
337
|
-
currentUrl.searchParams.delete('gitignore');
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// Navigate to the new URL
|
|
341
|
-
window.location.href = currentUrl.toString();
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// Ensure search hotkey label matches GitHub ('/')
|
|
346
|
-
if (searchHotkey) {
|
|
347
|
-
searchHotkey.textContent = '/';
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// Search functionality
|
|
351
|
-
if (searchInput) {
|
|
352
|
-
searchInput.addEventListener('input', function() {
|
|
353
|
-
const query = this.value.toLowerCase().trim();
|
|
354
|
-
filterFiles(query);
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
// Focus search with Ctrl+K or Cmd+K
|
|
358
|
-
document.addEventListener('keydown', function(e) {
|
|
359
|
-
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
|
|
360
|
-
e.preventDefault();
|
|
361
|
-
searchInput.focus();
|
|
362
|
-
searchInput.select();
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// Keyboard shortcuts help overlay
|
|
368
|
-
function showKeyboardHelp() {
|
|
369
|
-
// Remove existing help if present
|
|
370
|
-
const existingHelp = document.getElementById('keyboard-help');
|
|
371
|
-
if (existingHelp) {
|
|
372
|
-
existingHelp.remove();
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
const helpOverlay = document.createElement('div');
|
|
377
|
-
helpOverlay.id = 'keyboard-help';
|
|
378
|
-
helpOverlay.className = 'keyboard-help-overlay';
|
|
379
|
-
|
|
380
|
-
helpOverlay.innerHTML = `
|
|
381
|
-
<div class="keyboard-help-content">
|
|
382
|
-
<div class="keyboard-help-header">
|
|
383
|
-
<h2>Keyboard shortcuts</h2>
|
|
384
|
-
<button class="keyboard-help-close" aria-label="Close help">×</button>
|
|
385
|
-
</div>
|
|
386
|
-
<div class="keyboard-help-body">
|
|
387
|
-
<div class="shortcuts-container">
|
|
388
|
-
<div class="shortcut-section">
|
|
389
|
-
<h3>Repositories</h3>
|
|
390
|
-
<div class="shortcut-list">
|
|
391
|
-
<div class="shortcut-item">
|
|
392
|
-
<span class="shortcut-desc">Go to parent directory</span>
|
|
393
|
-
<div class="shortcut-keys"><kbd>H</kbd></div>
|
|
394
|
-
</div>
|
|
395
|
-
<div class="shortcut-item">
|
|
396
|
-
<span class="shortcut-desc">Toggle .gitignore filter</span>
|
|
397
|
-
<div class="shortcut-keys"><kbd>I</kbd></div>
|
|
398
|
-
</div>
|
|
399
|
-
<div class="shortcut-item">
|
|
400
|
-
<span class="shortcut-desc">Create new file</span>
|
|
401
|
-
<div class="shortcut-keys"><kbd>C</kbd></div>
|
|
402
|
-
</div>
|
|
403
|
-
<div class="shortcut-item">
|
|
404
|
-
<span class="shortcut-desc">Edit focused file</span>
|
|
405
|
-
<div class="shortcut-keys"><kbd>E</kbd></div>
|
|
406
|
-
</div>
|
|
407
|
-
<div class="shortcut-item">
|
|
408
|
-
<span class="shortcut-desc">Show diff for focused file</span>
|
|
409
|
-
<div class="shortcut-keys"><kbd>D</kbd></div>
|
|
410
|
-
</div>
|
|
411
|
-
<div class="shortcut-item">
|
|
412
|
-
<span class="shortcut-desc">Refresh page</span>
|
|
413
|
-
<div class="shortcut-keys"><kbd>R</kbd></div>
|
|
414
|
-
</div>
|
|
415
|
-
</div>
|
|
416
|
-
</div>
|
|
417
|
-
|
|
418
|
-
<div class="shortcut-section">
|
|
419
|
-
<h3>Site-wide shortcuts</h3>
|
|
420
|
-
<div class="shortcut-list">
|
|
421
|
-
<div class="shortcut-item">
|
|
422
|
-
<span class="shortcut-desc">Focus search</span>
|
|
423
|
-
<div class="shortcut-keys"><kbd>S</kbd> or <kbd>/</kbd></div>
|
|
424
|
-
</div>
|
|
425
|
-
<div class="shortcut-item">
|
|
426
|
-
<span class="shortcut-desc">Focus search</span>
|
|
427
|
-
<div class="shortcut-keys"><kbd>⌘</kbd> <kbd>K</kbd></div>
|
|
428
|
-
</div>
|
|
429
|
-
<div class="shortcut-item">
|
|
430
|
-
<span class="shortcut-desc">Toggle theme</span>
|
|
431
|
-
<div class="shortcut-keys"><kbd>T</kbd></div>
|
|
432
|
-
</div>
|
|
433
|
-
<div class="shortcut-item">
|
|
434
|
-
<span class="shortcut-desc">Bring up this help dialog</span>
|
|
435
|
-
<div class="shortcut-keys"><kbd>?</kbd></div>
|
|
436
|
-
</div>
|
|
437
|
-
<div class="shortcut-item">
|
|
438
|
-
<span class="shortcut-desc">Move selection down</span>
|
|
439
|
-
<div class="shortcut-keys"><kbd>J</kbd></div>
|
|
440
|
-
</div>
|
|
441
|
-
<div class="shortcut-item">
|
|
442
|
-
<span class="shortcut-desc">Move selection up</span>
|
|
443
|
-
<div class="shortcut-keys"><kbd>K</kbd></div>
|
|
444
|
-
</div>
|
|
445
|
-
<div class="shortcut-item">
|
|
446
|
-
<span class="shortcut-desc">Open selection</span>
|
|
447
|
-
<div class="shortcut-keys"><kbd>O</kbd> or <kbd>↵</kbd></div>
|
|
448
|
-
</div>
|
|
449
|
-
<div class="shortcut-item">
|
|
450
|
-
<span class="shortcut-desc">Save file (in editor)</span>
|
|
451
|
-
<div class="shortcut-keys"><kbd>⌘</kbd> <kbd>S</kbd></div>
|
|
452
|
-
</div>
|
|
453
|
-
<div class="shortcut-item">
|
|
454
|
-
<span class="shortcut-desc">Toggle word wrap (in editor)</span>
|
|
455
|
-
<div class="shortcut-keys"><kbd>Alt</kbd> <kbd>Z</kbd></div>
|
|
456
|
-
</div>
|
|
457
|
-
<div class="shortcut-item">
|
|
458
|
-
<span class="shortcut-desc">Close help/cancel</span>
|
|
459
|
-
<div class="shortcut-keys"><kbd>Esc</kbd></div>
|
|
460
|
-
</div>
|
|
461
|
-
</div>
|
|
462
|
-
</div>
|
|
463
|
-
</div>
|
|
464
|
-
</div>
|
|
465
|
-
</div>
|
|
466
|
-
`;
|
|
467
|
-
|
|
468
|
-
document.body.appendChild(helpOverlay);
|
|
469
|
-
|
|
470
|
-
// Close on click outside or escape
|
|
471
|
-
helpOverlay.addEventListener('click', function(e) {
|
|
472
|
-
if (e.target === helpOverlay) {
|
|
473
|
-
helpOverlay.remove();
|
|
474
|
-
}
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
helpOverlay.querySelector('.keyboard-help-close').addEventListener('click', function() {
|
|
478
|
-
helpOverlay.remove();
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
// Keyboard navigation
|
|
483
|
-
document.addEventListener('keydown', function(e) {
|
|
484
|
-
// Handle help overlay first
|
|
485
|
-
if (e.key === '?' && document.activeElement !== searchInput) {
|
|
486
|
-
e.preventDefault();
|
|
487
|
-
showKeyboardHelp();
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
// Close help with Escape
|
|
492
|
-
if (e.key === 'Escape') {
|
|
493
|
-
const helpOverlay = document.getElementById('keyboard-help');
|
|
494
|
-
if (helpOverlay) {
|
|
495
|
-
helpOverlay.remove();
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// Don't handle shortcuts when editor is active
|
|
501
|
-
const editorContainer = document.getElementById('editor-container');
|
|
502
|
-
if (editorContainer && editorContainer.style.display !== 'none' &&
|
|
503
|
-
editorContainer.contains(document.activeElement)) {
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
if (searchInput && document.activeElement === searchInput) {
|
|
508
|
-
handleSearchKeydown(e);
|
|
509
|
-
} else {
|
|
510
|
-
handleGlobalKeydown(e);
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
// New file and folder functionality
|
|
515
|
-
const newFileBtn = document.getElementById('new-file-btn');
|
|
516
|
-
const newFolderBtn = document.getElementById('new-folder-btn');
|
|
517
|
-
|
|
518
|
-
if (newFileBtn) {
|
|
519
|
-
newFileBtn.addEventListener('click', function() {
|
|
520
|
-
const currentPath = PathUtils.getCurrentPath();
|
|
521
|
-
|
|
522
|
-
// Navigate to new file creation mode
|
|
523
|
-
window.location.href = PathUtils.buildPathUrl('/new', currentPath);
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
if (newFolderBtn) {
|
|
528
|
-
newFolderBtn.addEventListener('click', function() {
|
|
529
|
-
const foldername = prompt('Enter folder name:');
|
|
530
|
-
if (foldername && foldername.trim()) {
|
|
531
|
-
const currentUrl = new URL(window.location.href);
|
|
532
|
-
const currentPath = currentUrl.searchParams.get('path') || '';
|
|
533
|
-
|
|
534
|
-
fetch('/api/create-folder', {
|
|
535
|
-
method: 'POST',
|
|
536
|
-
headers: {
|
|
537
|
-
'Content-Type': 'application/json',
|
|
538
|
-
},
|
|
539
|
-
body: JSON.stringify({
|
|
540
|
-
path: currentPath,
|
|
541
|
-
foldername: foldername.trim()
|
|
542
|
-
})
|
|
543
|
-
})
|
|
544
|
-
.then(response => response.json())
|
|
545
|
-
.then(data => {
|
|
546
|
-
if (data.success) {
|
|
547
|
-
// Refresh the current directory view
|
|
548
|
-
window.location.reload();
|
|
549
|
-
} else {
|
|
550
|
-
alert('Failed to create folder: ' + data.error);
|
|
551
|
-
}
|
|
552
|
-
})
|
|
553
|
-
.catch(error => {
|
|
554
|
-
console.error('Error creating folder:', error);
|
|
555
|
-
alert('Failed to create folder');
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
// File row click navigation
|
|
562
|
-
fileRows.forEach((row, index) => {
|
|
563
|
-
row.addEventListener('click', function(e) {
|
|
564
|
-
// Don't navigate if clicking on quick actions
|
|
565
|
-
if (e.target.closest('.quick-actions')) {
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
const link = row.querySelector('a');
|
|
570
|
-
if (link) {
|
|
571
|
-
link.click();
|
|
572
|
-
}
|
|
573
|
-
});
|
|
574
|
-
});
|
|
575
|
-
|
|
576
|
-
// Quick actions functionality
|
|
577
|
-
document.addEventListener('click', function(e) {
|
|
578
|
-
if (e.target.closest('.copy-path-btn')) {
|
|
579
|
-
e.preventDefault();
|
|
580
|
-
e.stopPropagation();
|
|
581
|
-
const button = e.target.closest('.copy-path-btn');
|
|
582
|
-
const path = button.dataset.path;
|
|
583
|
-
copyToClipboard(path, button);
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
// Line selection functionality
|
|
588
|
-
let lastClickedLine = null;
|
|
589
|
-
document.addEventListener('click', function(e) {
|
|
590
|
-
if (e.target.classList.contains('line-number')) {
|
|
591
|
-
e.preventDefault();
|
|
592
|
-
const lineContainer = e.target.closest('.line-container');
|
|
593
|
-
const lineNum = parseInt(lineContainer.dataset.line);
|
|
594
|
-
|
|
595
|
-
if (e.shiftKey && lastClickedLine !== null) {
|
|
596
|
-
// Range selection
|
|
597
|
-
selectLineRange(Math.min(lastClickedLine, lineNum), Math.max(lastClickedLine, lineNum));
|
|
598
|
-
} else if (e.ctrlKey || e.metaKey) {
|
|
599
|
-
// Toggle individual line
|
|
600
|
-
toggleLineSelection(lineNum);
|
|
601
|
-
} else {
|
|
602
|
-
// Single line selection
|
|
603
|
-
clearAllSelections();
|
|
604
|
-
selectLine(lineNum);
|
|
605
|
-
lastClickedLine = lineNum;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
updateURL();
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
function updateThemeIcon(theme) {
|
|
613
|
-
const iconSvg = themeToggle.querySelector('.theme-icon');
|
|
614
|
-
if (iconSvg) {
|
|
615
|
-
if (theme === 'dark') {
|
|
616
|
-
iconSvg.innerHTML = '<path d="M8 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM8 0a.75.75 0 0 1 .75.75v1.5a.75.75 0 0 1-1.5 0V.75A.75.75 0 0 1 8 0zm0 13a.75.75 0 0 1 .75.75v1.5a.75.75 0 0 1-1.5 0v-1.5A.75.75 0 0 1 8 13zM2.343 2.343a.75.75 0 0 1 1.061 0l1.06 1.061a.75.75 0 0 1-1.06 1.06l-1.06-1.06a.75.75 0 0 1 0-1.061zm9.193 9.193a.75.75 0 0 1 1.06 0l1.061 1.06a.75.75 0 0 1-1.06 1.061l-1.061-1.06a.75.75 0 0 1 0-1.061zM16 8a.75.75 0 0 1-.75.75h-1.5a.75.75 0 0 1 0-1.5h1.5A.75.75 0 0 1 16 8zM3 8a.75.75 0 0 1-.75.75H.75a.75.75 0 0 1 0-1.5h1.5A.75.75 0 0 1 3 8zm10.657-5.657a.75.75 0 0 1 0 1.061l-1.061 1.06a.75.75 0 1 1-1.06-1.06l1.06-1.06a.75.75 0 0 1 1.061 0zm-9.193 9.193a.75.75 0 0 1 0 1.06l-1.06 1.061a.75.75 0 1 1-1.061-1.06l1.06-1.061a.75.75 0 0 1 1.061 0z"></path>';
|
|
617
|
-
} else {
|
|
618
|
-
iconSvg.innerHTML = '<path d="M9.598 1.591a.75.75 0 0 1 .785-.175 7 7 0 1 1-8.967 8.967.75.75 0 0 1 .961-.96 5.5 5.5 0 0 0 7.046-7.046.75.75 0 0 1 .175-.786zm1.616 1.945a7 7 0 0 1-7.678 7.678 5.5 5.5 0 1 0 7.678-7.678z"></path>';
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
function updateFileRows() {
|
|
624
|
-
if (fileTable) {
|
|
625
|
-
fileRows = Array.from(fileTable.querySelectorAll('.file-row'));
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
function filterFiles(query) {
|
|
630
|
-
if (!query) {
|
|
631
|
-
fileRows.forEach(row => {
|
|
632
|
-
row.classList.remove('hidden');
|
|
633
|
-
});
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
fileRows.forEach(row => {
|
|
638
|
-
const fileName = row.dataset.name;
|
|
639
|
-
const isVisible = fileName.includes(query);
|
|
640
|
-
row.classList.toggle('hidden', !isVisible);
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
// Reset focus when filtering
|
|
644
|
-
clearFocus();
|
|
645
|
-
currentFocusIndex = -1;
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
function handleSearchKeydown(e) {
|
|
649
|
-
switch(e.key) {
|
|
650
|
-
case 'Escape':
|
|
651
|
-
searchInput.blur();
|
|
652
|
-
searchInput.value = '';
|
|
653
|
-
filterFiles('');
|
|
654
|
-
break;
|
|
655
|
-
case 'ArrowDown':
|
|
656
|
-
e.preventDefault();
|
|
657
|
-
searchInput.blur();
|
|
658
|
-
focusFirstVisibleRow();
|
|
659
|
-
break;
|
|
660
|
-
case 'Enter':
|
|
661
|
-
if (searchInput.value.trim()) {
|
|
662
|
-
const firstVisible = getVisibleRows()[0];
|
|
663
|
-
if (firstVisible) {
|
|
664
|
-
const link = firstVisible.querySelector('a');
|
|
665
|
-
if (link) link.click();
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
break;
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
function handleGlobalKeydown(e) {
|
|
673
|
-
const visibleRows = getVisibleRows();
|
|
674
|
-
|
|
675
|
-
switch(e.key) {
|
|
676
|
-
case 'ArrowDown':
|
|
677
|
-
case 'j':
|
|
678
|
-
e.preventDefault();
|
|
679
|
-
navigateDown(visibleRows);
|
|
680
|
-
break;
|
|
681
|
-
case 'ArrowUp':
|
|
682
|
-
case 'k':
|
|
683
|
-
e.preventDefault();
|
|
684
|
-
navigateUp(visibleRows);
|
|
685
|
-
break;
|
|
686
|
-
case 'Enter':
|
|
687
|
-
case 'o':
|
|
688
|
-
if (currentFocusIndex >= 0 && visibleRows[currentFocusIndex]) {
|
|
689
|
-
const link = visibleRows[currentFocusIndex].querySelector('a');
|
|
690
|
-
if (link) link.click();
|
|
691
|
-
}
|
|
692
|
-
break;
|
|
693
|
-
case '/':
|
|
694
|
-
case 's':
|
|
695
|
-
if (searchInput && !e.ctrlKey && !e.metaKey) {
|
|
696
|
-
e.preventDefault();
|
|
697
|
-
searchInput.focus();
|
|
698
|
-
}
|
|
699
|
-
break;
|
|
700
|
-
case 'g':
|
|
701
|
-
if (e.ctrlKey || e.metaKey) {
|
|
702
|
-
e.preventDefault();
|
|
703
|
-
if (visibleRows.length > 0) {
|
|
704
|
-
currentFocusIndex = 0;
|
|
705
|
-
updateFocus(visibleRows);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
break;
|
|
709
|
-
case 'G':
|
|
710
|
-
if (e.shiftKey) {
|
|
711
|
-
e.preventDefault();
|
|
712
|
-
if (visibleRows.length > 0) {
|
|
713
|
-
currentFocusIndex = visibleRows.length - 1;
|
|
714
|
-
updateFocus(visibleRows);
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
break;
|
|
718
|
-
case 'h':
|
|
719
|
-
// Go back/up one directory
|
|
720
|
-
e.preventDefault();
|
|
721
|
-
goUpDirectory();
|
|
722
|
-
break;
|
|
723
|
-
case 'r':
|
|
724
|
-
// Refresh page
|
|
725
|
-
if (!e.ctrlKey && !e.metaKey) {
|
|
726
|
-
e.preventDefault();
|
|
727
|
-
location.reload();
|
|
728
|
-
}
|
|
729
|
-
break;
|
|
730
|
-
case 't':
|
|
731
|
-
// Toggle theme
|
|
732
|
-
if (!e.ctrlKey && !e.metaKey) {
|
|
733
|
-
e.preventDefault();
|
|
734
|
-
themeToggle.click();
|
|
735
|
-
}
|
|
736
|
-
break;
|
|
737
|
-
case '?':
|
|
738
|
-
// Show keyboard shortcuts help
|
|
739
|
-
e.preventDefault();
|
|
740
|
-
showKeyboardHelp();
|
|
741
|
-
break;
|
|
742
|
-
case 'c':
|
|
743
|
-
// Create new file
|
|
744
|
-
if (!e.ctrlKey && !e.metaKey) {
|
|
745
|
-
e.preventDefault();
|
|
746
|
-
const newFileBtn = document.getElementById('new-file-btn');
|
|
747
|
-
if (newFileBtn) {
|
|
748
|
-
newFileBtn.click();
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
break;
|
|
752
|
-
case 'e':
|
|
753
|
-
// Edit focused file
|
|
754
|
-
if (!e.ctrlKey && !e.metaKey && currentFocusIndex >= 0 && visibleRows[currentFocusIndex]) {
|
|
755
|
-
e.preventDefault();
|
|
756
|
-
const focusedRow = visibleRows[currentFocusIndex];
|
|
757
|
-
const rowType = focusedRow.dataset.type;
|
|
758
|
-
|
|
759
|
-
// If we're in a directory listing and focused on a file
|
|
760
|
-
if (rowType === 'file') {
|
|
761
|
-
const filePath = focusedRow.dataset.path;
|
|
762
|
-
// Navigate to the file and trigger edit mode
|
|
763
|
-
window.location.href = PathUtils.buildPathUrl('/', filePath) + '#edit';
|
|
764
|
-
} else {
|
|
765
|
-
// If we're on a file page, use the edit button
|
|
766
|
-
const editBtn = document.getElementById('edit-btn');
|
|
767
|
-
if (editBtn && editBtn.style.display !== 'none') {
|
|
768
|
-
editBtn.click();
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
break;
|
|
773
|
-
case 'i':
|
|
774
|
-
// Toggle gitignore
|
|
775
|
-
if (!e.ctrlKey && !e.metaKey) {
|
|
776
|
-
e.preventDefault();
|
|
777
|
-
const gitignoreToggle = document.getElementById('gitignore-toggle');
|
|
778
|
-
if (gitignoreToggle) {
|
|
779
|
-
gitignoreToggle.click();
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
break;
|
|
783
|
-
case 'd':
|
|
784
|
-
// Show diff for focused file (if it has git status)
|
|
785
|
-
if (!e.ctrlKey && !e.metaKey && currentFocusIndex >= 0 && visibleRows[currentFocusIndex]) {
|
|
786
|
-
e.preventDefault();
|
|
787
|
-
const focusedRow = visibleRows[currentFocusIndex];
|
|
788
|
-
const rowType = focusedRow.dataset.type;
|
|
789
|
-
|
|
790
|
-
if (rowType === 'file') {
|
|
791
|
-
const filePath = focusedRow.dataset.path;
|
|
792
|
-
const diffBtn = focusedRow.querySelector('.diff-btn');
|
|
793
|
-
if (diffBtn) {
|
|
794
|
-
showDiffViewer(filePath);
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
break;
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
function getVisibleRows() {
|
|
803
|
-
return fileRows.filter(row => !row.classList.contains('hidden'));
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
function focusFirstVisibleRow() {
|
|
807
|
-
const visibleRows = getVisibleRows();
|
|
808
|
-
if (visibleRows.length > 0) {
|
|
809
|
-
currentFocusIndex = 0;
|
|
810
|
-
updateFocus(visibleRows);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
function navigateDown(visibleRows) {
|
|
815
|
-
if (visibleRows.length === 0) return;
|
|
816
|
-
|
|
817
|
-
currentFocusIndex++;
|
|
818
|
-
if (currentFocusIndex >= visibleRows.length) {
|
|
819
|
-
currentFocusIndex = 0;
|
|
820
|
-
}
|
|
821
|
-
updateFocus(visibleRows);
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
function navigateUp(visibleRows) {
|
|
825
|
-
if (visibleRows.length === 0) return;
|
|
826
|
-
|
|
827
|
-
currentFocusIndex--;
|
|
828
|
-
if (currentFocusIndex < 0) {
|
|
829
|
-
currentFocusIndex = visibleRows.length - 1;
|
|
830
|
-
}
|
|
831
|
-
updateFocus(visibleRows);
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
function updateFocus(visibleRows) {
|
|
835
|
-
clearFocus();
|
|
836
|
-
if (currentFocusIndex >= 0 && visibleRows[currentFocusIndex]) {
|
|
837
|
-
visibleRows[currentFocusIndex].classList.add('focused');
|
|
838
|
-
visibleRows[currentFocusIndex].scrollIntoView({
|
|
839
|
-
block: 'nearest',
|
|
840
|
-
behavior: 'smooth'
|
|
841
|
-
});
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
function clearFocus() {
|
|
846
|
-
fileRows.forEach(row => row.classList.remove('focused'));
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
function goUpDirectory() {
|
|
850
|
-
const currentPath = PathUtils.getCurrentPath();
|
|
851
|
-
const newPath = PathUtils.getParentPath(currentPath);
|
|
852
|
-
|
|
853
|
-
if (newPath === null) {
|
|
854
|
-
// Already at root, do nothing
|
|
855
|
-
return;
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
window.location.href = PathUtils.buildPathUrl('/', newPath);
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
function selectLine(lineNum) {
|
|
863
|
-
const lineContainer = document.querySelector(`[data-line="${lineNum}"]`);
|
|
864
|
-
if (lineContainer) {
|
|
865
|
-
lineContainer.classList.add('selected');
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
function toggleLineSelection(lineNum) {
|
|
870
|
-
const lineContainer = document.querySelector(`[data-line="${lineNum}"]`);
|
|
871
|
-
if (lineContainer) {
|
|
872
|
-
lineContainer.classList.toggle('selected');
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
function selectLineRange(startLine, endLine) {
|
|
877
|
-
clearAllSelections();
|
|
878
|
-
for (let i = startLine; i <= endLine; i++) {
|
|
879
|
-
selectLine(i);
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
function clearAllSelections() {
|
|
884
|
-
document.querySelectorAll('.line-container.selected').forEach(line => {
|
|
885
|
-
line.classList.remove('selected');
|
|
886
|
-
});
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
function updateURL() {
|
|
890
|
-
const selectedLines = Array.from(document.querySelectorAll('.line-container.selected'))
|
|
891
|
-
.map(line => parseInt(line.dataset.line))
|
|
892
|
-
.sort((a, b) => a - b);
|
|
893
|
-
|
|
894
|
-
const url = new URL(window.location);
|
|
895
|
-
|
|
896
|
-
if (selectedLines.length === 0) {
|
|
897
|
-
url.hash = '';
|
|
898
|
-
} else if (selectedLines.length === 1) {
|
|
899
|
-
url.hash = `#L${selectedLines[0]}`;
|
|
900
|
-
} else {
|
|
901
|
-
// Find ranges
|
|
902
|
-
const ranges = [];
|
|
903
|
-
let rangeStart = selectedLines[0];
|
|
904
|
-
let rangeEnd = selectedLines[0];
|
|
905
|
-
|
|
906
|
-
for (let i = 1; i < selectedLines.length; i++) {
|
|
907
|
-
if (selectedLines[i] === rangeEnd + 1) {
|
|
908
|
-
rangeEnd = selectedLines[i];
|
|
909
|
-
} else {
|
|
910
|
-
if (rangeStart === rangeEnd) {
|
|
911
|
-
ranges.push(`L${rangeStart}`);
|
|
912
|
-
} else {
|
|
913
|
-
ranges.push(`L${rangeStart}-L${rangeEnd}`);
|
|
914
|
-
}
|
|
915
|
-
rangeStart = rangeEnd = selectedLines[i];
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
if (rangeStart === rangeEnd) {
|
|
920
|
-
ranges.push(`L${rangeStart}`);
|
|
921
|
-
} else {
|
|
922
|
-
ranges.push(`L${rangeStart}-L${rangeEnd}`);
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
url.hash = `#${ranges.join(',')}`;
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
window.history.replaceState({}, '', url);
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
// Initialize line selections from URL on page load
|
|
932
|
-
function initLineSelections() {
|
|
933
|
-
const hash = window.location.hash.slice(1);
|
|
934
|
-
if (!hash) return;
|
|
935
|
-
|
|
936
|
-
const parts = hash.split(',');
|
|
937
|
-
parts.forEach(part => {
|
|
938
|
-
if (part.includes('-')) {
|
|
939
|
-
const [start, end] = part.split('-').map(p => parseInt(p.replace('L', '')));
|
|
940
|
-
selectLineRange(start, end);
|
|
941
|
-
} else {
|
|
942
|
-
const lineNum = parseInt(part.replace('L', ''));
|
|
943
|
-
selectLine(lineNum);
|
|
944
|
-
}
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
// Initialize line selections if we're on a file page
|
|
949
|
-
if (document.querySelector('.with-line-numbers')) {
|
|
950
|
-
initLineSelections();
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
// Editor functionality
|
|
954
|
-
const editBtn = document.getElementById('edit-btn');
|
|
955
|
-
const editorContainer = document.getElementById('editor-container');
|
|
956
|
-
const saveBtn = document.getElementById('save-btn');
|
|
957
|
-
const cancelBtn = document.getElementById('cancel-btn');
|
|
958
|
-
const wordWrapBtn = document.getElementById('word-wrap-btn');
|
|
959
|
-
const fileContent = document.querySelector('.file-content');
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
// Auto-open editor if hash is #edit
|
|
964
|
-
if (window.location.hash === '#edit' && editBtn) {
|
|
965
|
-
// Remove hash and trigger edit
|
|
966
|
-
window.location.hash = '';
|
|
967
|
-
setTimeout(() => editBtn.click(), 100);
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
if (editBtn && editorContainer) {
|
|
971
|
-
let originalContent = '';
|
|
972
|
-
let wordWrapEnabled = false; // Default to disabled
|
|
973
|
-
|
|
974
|
-
// Word wrap toggle functionality
|
|
975
|
-
function toggleWordWrap() {
|
|
976
|
-
if (monacoFileEditor) {
|
|
977
|
-
wordWrapEnabled = !wordWrapEnabled;
|
|
978
|
-
monacoFileEditor.updateOptions({ wordWrap: wordWrapEnabled ? 'on' : 'off' });
|
|
979
|
-
|
|
980
|
-
// Update button appearance
|
|
981
|
-
if (wordWrapBtn) {
|
|
982
|
-
wordWrapBtn.classList.toggle('btn-primary', wordWrapEnabled);
|
|
983
|
-
wordWrapBtn.classList.toggle('btn-secondary', !wordWrapEnabled);
|
|
984
|
-
wordWrapBtn.textContent = wordWrapEnabled ? '↩ Wrap ON' : '↩ Wrap OFF';
|
|
985
|
-
wordWrapBtn.title = `Toggle word wrap (Alt+Z) - ${wordWrapEnabled ? 'ON' : 'OFF'}`;
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
// Word wrap button click
|
|
991
|
-
if (wordWrapBtn) {
|
|
992
|
-
wordWrapBtn.addEventListener('click', toggleWordWrap);
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
// Editor keyboard shortcuts
|
|
996
|
-
document.addEventListener('keydown', function(e) {
|
|
997
|
-
if (editorContainer && editorContainer.style.display !== 'none') {
|
|
998
|
-
// Cmd/Ctrl+S to save
|
|
999
|
-
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
|
|
1000
|
-
e.preventDefault();
|
|
1001
|
-
saveBtn.click();
|
|
1002
|
-
}
|
|
1003
|
-
// Alt+Z to toggle word wrap
|
|
1004
|
-
if (e.altKey && e.key === 'z') {
|
|
1005
|
-
e.preventDefault();
|
|
1006
|
-
toggleWordWrap();
|
|
1007
|
-
}
|
|
1008
|
-
// Escape to cancel
|
|
1009
|
-
if (e.key === 'Escape') {
|
|
1010
|
-
e.preventDefault();
|
|
1011
|
-
cancelBtn.click();
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
});
|
|
1015
|
-
|
|
1016
|
-
// Note: Draft management functions are now in global DraftManager object
|
|
1017
|
-
|
|
1018
|
-
// Show draft dialog with Load/Discard/Cancel options
|
|
1019
|
-
function showDraftDialog(filePath) {
|
|
1020
|
-
return new Promise((resolve) => {
|
|
1021
|
-
const modal = document.createElement('div');
|
|
1022
|
-
modal.className = 'modal-overlay';
|
|
1023
|
-
modal.innerHTML = `
|
|
1024
|
-
<div class="modal-content draft-modal">
|
|
1025
|
-
<h3>Unsaved Changes Found</h3>
|
|
1026
|
-
<p>You have unsaved changes for this file. What would you like to do?</p>
|
|
1027
|
-
<div class="draft-actions">
|
|
1028
|
-
<button class="btn btn-primary" data-action="load">Load Draft</button>
|
|
1029
|
-
<button class="btn btn-secondary" data-action="discard">Discard Draft</button>
|
|
1030
|
-
<button class="btn btn-secondary" data-action="cancel">Cancel</button>
|
|
1031
|
-
</div>
|
|
1032
|
-
</div>
|
|
1033
|
-
`;
|
|
1034
|
-
|
|
1035
|
-
modal.addEventListener('click', (e) => {
|
|
1036
|
-
if (e.target.matches('[data-action]') || e.target === modal) {
|
|
1037
|
-
const action = e.target.dataset?.action || 'cancel';
|
|
1038
|
-
modal.remove();
|
|
1039
|
-
resolve(action);
|
|
1040
|
-
}
|
|
1041
|
-
});
|
|
1042
|
-
|
|
1043
|
-
document.body.appendChild(modal);
|
|
1044
|
-
});
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
editBtn.addEventListener('click', async function() {
|
|
1048
|
-
// Get current file path
|
|
1049
|
-
const currentUrl = new URL(window.location.href);
|
|
1050
|
-
const filePath = currentUrl.searchParams.get('path') || '';
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
// Fetch original file content
|
|
1054
|
-
try {
|
|
1055
|
-
const response = await fetch(`/api/file-content?path=${encodeURIComponent(filePath)}`);
|
|
1056
|
-
if (!response.ok) {
|
|
1057
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
1058
|
-
}
|
|
1059
|
-
const content = await response.text();
|
|
1060
|
-
originalContent = content;
|
|
1061
|
-
|
|
1062
|
-
// Check for draft
|
|
1063
|
-
const draft = DraftManager.loadDraft(filePath);
|
|
1064
|
-
let contentToLoad = content;
|
|
1065
|
-
|
|
1066
|
-
if (DraftManager.hasDraftChanges(filePath, content)) {
|
|
1067
|
-
// Show custom draft dialog with 3 options
|
|
1068
|
-
const draftChoice = await showDraftDialog(filePath);
|
|
1069
|
-
if (draftChoice === 'load') {
|
|
1070
|
-
contentToLoad = draft;
|
|
1071
|
-
} else if (draftChoice === 'discard') {
|
|
1072
|
-
DraftManager.clearDraft(filePath);
|
|
1073
|
-
contentToLoad = content;
|
|
1074
|
-
} else {
|
|
1075
|
-
// User cancelled, use original content
|
|
1076
|
-
contentToLoad = content;
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
if (draft && draft === content) {
|
|
1081
|
-
DraftManager.clearDraft(filePath);
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
// Create Monaco editor if it doesn't exist
|
|
1085
|
-
if (!monacoFileEditor && window.monacoReady) {
|
|
1086
|
-
const fileEditorContainer = document.getElementById('file-editor');
|
|
1087
|
-
if (fileEditorContainer) {
|
|
1088
|
-
// Get filename reliably from the current URL path parameter
|
|
1089
|
-
const currentUrl = new URL(window.location.href);
|
|
1090
|
-
const filePath = currentUrl.searchParams.get('path') || '';
|
|
1091
|
-
const filename = PathUtils.getFileName(filePath);
|
|
1092
|
-
|
|
1093
|
-
const language = getLanguageFromExtension(filename);
|
|
1094
|
-
|
|
1095
|
-
// Validate language exists in Monaco
|
|
1096
|
-
const availableLanguages = monaco.languages.getLanguages().map(lang => lang.id);
|
|
1097
|
-
const validLanguage = availableLanguages.includes(language) ? language : 'plaintext';
|
|
1098
|
-
|
|
1099
|
-
const currentTheme = html.getAttribute('data-theme');
|
|
1100
|
-
const monacoTheme = currentTheme === 'dark' ? 'vs-dark' : 'vs';
|
|
1101
|
-
|
|
1102
|
-
// Ensure Monaco is fully ready before creating editor
|
|
1103
|
-
const createEditorWhenReady = () => {
|
|
1104
|
-
if (monaco && monaco.editor && monaco.languages) {
|
|
1105
|
-
monacoFileEditor = monaco.editor.create(fileEditorContainer, {
|
|
1106
|
-
value: '',
|
|
1107
|
-
language: validLanguage,
|
|
1108
|
-
theme: monacoTheme,
|
|
1109
|
-
minimap: { enabled: false },
|
|
1110
|
-
lineNumbers: 'on',
|
|
1111
|
-
wordWrap: 'off',
|
|
1112
|
-
scrollBeyondLastLine: false,
|
|
1113
|
-
fontSize: 12,
|
|
1114
|
-
lineHeight: 20, // Match view mode (12px * 1.5 = 18, but Monaco uses pixels)
|
|
1115
|
-
fontFamily: "'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace",
|
|
1116
|
-
padding: { top: 20, bottom: 20, left: 20, right: 20 },
|
|
1117
|
-
renderLineHighlight: 'line',
|
|
1118
|
-
selectOnLineNumbers: true,
|
|
1119
|
-
automaticLayout: true,
|
|
1120
|
-
folding: true,
|
|
1121
|
-
foldingHighlight: true,
|
|
1122
|
-
foldingStrategy: 'auto',
|
|
1123
|
-
showFoldingControls: 'mouseover',
|
|
1124
|
-
bracketPairColorization: { enabled: true },
|
|
1125
|
-
guides: {
|
|
1126
|
-
bracketPairs: true,
|
|
1127
|
-
indentation: true
|
|
1128
|
-
}
|
|
1129
|
-
});
|
|
1130
|
-
} else {
|
|
1131
|
-
// Monaco not fully ready yet, retry
|
|
1132
|
-
setTimeout(createEditorWhenReady, 10);
|
|
1133
|
-
}
|
|
1134
|
-
};
|
|
1135
|
-
|
|
1136
|
-
// Start the ready check
|
|
1137
|
-
createEditorWhenReady();
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
// Set content in Monaco editor - wait for Monaco to be ready
|
|
1142
|
-
const setContentWhenReady = () => {
|
|
1143
|
-
if (monacoFileEditor && window.monacoReady) {
|
|
1144
|
-
// Make sure the editor is visible and properly sized
|
|
1145
|
-
monacoFileEditor.layout();
|
|
1146
|
-
monacoFileEditor.setValue(contentToLoad);
|
|
1147
|
-
|
|
1148
|
-
// Force another layout after a brief delay to ensure proper sizing
|
|
1149
|
-
setTimeout(() => {
|
|
1150
|
-
monacoFileEditor.layout();
|
|
1151
|
-
}, 50);
|
|
1152
|
-
|
|
1153
|
-
// Language is already set during editor creation, no need to set it again
|
|
1154
|
-
|
|
1155
|
-
// Set up auto-save
|
|
1156
|
-
monacoFileEditor.onDidChangeModelContent(() => {
|
|
1157
|
-
DraftManager.saveDraft(filePath, monacoFileEditor.getValue());
|
|
1158
|
-
});
|
|
1159
|
-
} else {
|
|
1160
|
-
// Monaco not ready yet, wait and try again
|
|
1161
|
-
setTimeout(setContentWhenReady, 100);
|
|
1162
|
-
}
|
|
1163
|
-
};
|
|
1164
|
-
setContentWhenReady();
|
|
1165
|
-
|
|
1166
|
-
// Show editor UI
|
|
1167
|
-
fileContent.style.display = 'none';
|
|
1168
|
-
editorContainer.style.display = 'block';
|
|
1169
|
-
|
|
1170
|
-
// Focus Monaco editor
|
|
1171
|
-
if (monacoFileEditor) {
|
|
1172
|
-
monacoFileEditor.focus();
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
} catch (error) {
|
|
1176
|
-
console.error('Error fetching file content:', error);
|
|
1177
|
-
let errorMessage = 'Failed to load file content for editing';
|
|
1178
|
-
if (error.message.includes('HTTP 403')) {
|
|
1179
|
-
errorMessage = 'Access denied: Cannot read this file';
|
|
1180
|
-
} else if (error.message.includes('HTTP 404')) {
|
|
1181
|
-
errorMessage = 'File not found';
|
|
1182
|
-
} else if (error.message.includes('NetworkError') || error.message.includes('Failed to fetch')) {
|
|
1183
|
-
errorMessage = 'Network error: Please check your connection';
|
|
1184
|
-
}
|
|
1185
|
-
showNotification(errorMessage, 'error');
|
|
1186
|
-
}
|
|
1187
|
-
});
|
|
1188
|
-
|
|
1189
|
-
cancelBtn.addEventListener('click', function() {
|
|
1190
|
-
editorContainer.style.display = 'none';
|
|
1191
|
-
fileContent.style.display = 'block';
|
|
1192
|
-
});
|
|
1193
|
-
|
|
1194
|
-
saveBtn.addEventListener('click', function() {
|
|
1195
|
-
const currentUrl = new URL(window.location.href);
|
|
1196
|
-
const filePath = currentUrl.searchParams.get('path') || '';
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
fetch('/api/save-file', {
|
|
1200
|
-
method: 'POST',
|
|
1201
|
-
headers: {
|
|
1202
|
-
'Content-Type': 'application/json',
|
|
1203
|
-
},
|
|
1204
|
-
body: JSON.stringify({
|
|
1205
|
-
path: filePath,
|
|
1206
|
-
content: monacoFileEditor ? monacoFileEditor.getValue() : ''
|
|
1207
|
-
})
|
|
1208
|
-
})
|
|
1209
|
-
.then(response => {
|
|
1210
|
-
if (!response.ok) {
|
|
1211
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
1212
|
-
}
|
|
1213
|
-
return response.json();
|
|
1214
|
-
})
|
|
1215
|
-
.then(data => {
|
|
1216
|
-
if (data.success) {
|
|
1217
|
-
// Clear draft on successful save
|
|
1218
|
-
DraftManager.clearDraft(filePath);
|
|
1219
|
-
// Refresh the page to show updated content
|
|
1220
|
-
window.location.reload();
|
|
1221
|
-
} else {
|
|
1222
|
-
showNotification('Failed to save file: ' + data.error, 'error');
|
|
1223
|
-
}
|
|
1224
|
-
})
|
|
1225
|
-
.catch(error => {
|
|
1226
|
-
console.error('Error saving file:', error);
|
|
1227
|
-
let errorMessage = 'Failed to save file';
|
|
1228
|
-
if (error.message.includes('HTTP 403')) {
|
|
1229
|
-
errorMessage = 'Access denied: Cannot write to this file';
|
|
1230
|
-
} else if (error.message.includes('HTTP 413')) {
|
|
1231
|
-
errorMessage = 'File too large to save';
|
|
1232
|
-
} else if (error.message.includes('NetworkError') || error.message.includes('Failed to fetch')) {
|
|
1233
|
-
errorMessage = 'Network error: Please check your connection';
|
|
1234
|
-
}
|
|
1235
|
-
showNotification(errorMessage, 'error');
|
|
1236
|
-
});
|
|
1237
|
-
});
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
// Quick edit file functionality
|
|
1241
|
-
document.addEventListener('click', function(e) {
|
|
1242
|
-
if (e.target.closest('.edit-file-btn')) {
|
|
1243
|
-
e.preventDefault();
|
|
1244
|
-
e.stopPropagation();
|
|
1245
|
-
const button = e.target.closest('.edit-file-btn');
|
|
1246
|
-
const filePath = button.dataset.path;
|
|
1247
|
-
// Navigate to the file and trigger edit mode
|
|
1248
|
-
window.location.href = PathUtils.buildPathUrl('/', filePath) + '#edit';
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
// Git diff viewer functionality
|
|
1252
|
-
if (e.target.closest('.diff-btn')) {
|
|
1253
|
-
e.preventDefault();
|
|
1254
|
-
e.stopPropagation();
|
|
1255
|
-
const button = e.target.closest('.diff-btn');
|
|
1256
|
-
const filePath = button.dataset.path;
|
|
1257
|
-
showDiffViewer(filePath);
|
|
1258
|
-
}
|
|
1259
|
-
});
|
|
1260
|
-
|
|
1261
|
-
// Git diff viewer functions
|
|
1262
|
-
function showDiffViewer(filePath) {
|
|
1263
|
-
// Create diff viewer overlay
|
|
1264
|
-
const overlay = document.createElement('div');
|
|
1265
|
-
overlay.className = 'diff-viewer-overlay';
|
|
1266
|
-
overlay.innerHTML = `
|
|
1267
|
-
<div class="diff-viewer-modal">
|
|
1268
|
-
<div class="diff-viewer-header">
|
|
1269
|
-
<h3 class="diff-viewer-title">
|
|
1270
|
-
📋 Diff: ${filePath}
|
|
1271
|
-
</h3>
|
|
1272
|
-
<button class="diff-close-btn" aria-label="Close diff viewer">×</button>
|
|
1273
|
-
</div>
|
|
1274
|
-
<div class="diff-viewer-content">
|
|
1275
|
-
<div style="padding: 40px; text-align: center;">Fetching diff...</div>
|
|
1276
|
-
</div>
|
|
1277
|
-
</div>
|
|
1278
|
-
`;
|
|
1279
|
-
|
|
1280
|
-
document.body.appendChild(overlay);
|
|
1281
|
-
|
|
1282
|
-
// Close on overlay click or close button
|
|
1283
|
-
overlay.addEventListener('click', function(e) {
|
|
1284
|
-
if (e.target === overlay || e.target.classList.contains('diff-close-btn')) {
|
|
1285
|
-
document.body.removeChild(overlay);
|
|
1286
|
-
}
|
|
1287
|
-
});
|
|
1288
|
-
|
|
1289
|
-
// Close with Escape key
|
|
1290
|
-
const escHandler = function(e) {
|
|
1291
|
-
if (e.key === 'Escape') {
|
|
1292
|
-
document.body.removeChild(overlay);
|
|
1293
|
-
document.removeEventListener('keydown', escHandler);
|
|
1294
|
-
}
|
|
1295
|
-
};
|
|
1296
|
-
document.addEventListener('keydown', escHandler);
|
|
1297
|
-
|
|
1298
|
-
// Load diff content
|
|
1299
|
-
loadDiffContent(filePath, overlay);
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
|
-
function loadDiffContent(filePath, overlay) {
|
|
1303
|
-
fetch(`/api/git-diff?path=${encodeURIComponent(filePath)}`)
|
|
1304
|
-
.then(response => response.json())
|
|
1305
|
-
.then(data => {
|
|
1306
|
-
if (data.success) {
|
|
1307
|
-
renderDiff(data.diff, data.filePath, overlay);
|
|
1308
|
-
} else {
|
|
1309
|
-
showDiffError(data.error, overlay);
|
|
1310
|
-
}
|
|
1311
|
-
})
|
|
1312
|
-
.catch(error => {
|
|
1313
|
-
console.error('Error loading diff:', error);
|
|
1314
|
-
showDiffError('Failed to load diff', overlay);
|
|
1315
|
-
});
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
function renderDiff(diffText, filePath, overlay) {
|
|
1319
|
-
if (!diffText || diffText.trim() === '') {
|
|
1320
|
-
const content = overlay.querySelector('.diff-viewer-content');
|
|
1321
|
-
content.innerHTML = `
|
|
1322
|
-
<div style="padding: 40px; text-align: center; color: var(--text-secondary);">
|
|
1323
|
-
No changes detected for this file
|
|
1324
|
-
</div>
|
|
1325
|
-
`;
|
|
1326
|
-
return;
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
const lines = diffText.split('\n');
|
|
1330
|
-
const parsedDiff = parseDiff(lines);
|
|
1331
|
-
|
|
1332
|
-
const content = overlay.querySelector('.diff-viewer-content');
|
|
1333
|
-
content.innerHTML = `
|
|
1334
|
-
<div class="diff-container">
|
|
1335
|
-
<div class="diff-side">
|
|
1336
|
-
<div class="diff-side-header">Original</div>
|
|
1337
|
-
<div class="diff-side-content" id="diff-original"></div>
|
|
1338
|
-
</div>
|
|
1339
|
-
<div class="diff-side">
|
|
1340
|
-
<div class="diff-side-header">Modified</div>
|
|
1341
|
-
<div class="diff-side-content" id="diff-modified"></div>
|
|
1342
|
-
</div>
|
|
1343
|
-
</div>
|
|
1344
|
-
`;
|
|
1345
|
-
|
|
1346
|
-
const originalSide = content.querySelector('#diff-original');
|
|
1347
|
-
const modifiedSide = content.querySelector('#diff-modified');
|
|
1348
|
-
|
|
1349
|
-
renderDiffSide(parsedDiff.original, originalSide, 'original');
|
|
1350
|
-
renderDiffSide(parsedDiff.modified, modifiedSide, 'modified');
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
function parseDiff(lines) {
|
|
1354
|
-
const original = [];
|
|
1355
|
-
const modified = [];
|
|
1356
|
-
let originalLineNum = 1;
|
|
1357
|
-
let modifiedLineNum = 1;
|
|
1358
|
-
|
|
1359
|
-
for (let i = 0; i < lines.length; i++) {
|
|
1360
|
-
const line = lines[i];
|
|
1361
|
-
|
|
1362
|
-
if (line.startsWith('@@')) {
|
|
1363
|
-
// Parse hunk header
|
|
1364
|
-
const match = line.match(/@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
|
|
1365
|
-
if (match) {
|
|
1366
|
-
originalLineNum = parseInt(match[1]);
|
|
1367
|
-
modifiedLineNum = parseInt(match[2]);
|
|
1368
|
-
}
|
|
1369
|
-
continue;
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
if (line.startsWith('---') || line.startsWith('+++') || line.startsWith('diff ') || line.startsWith('index ')) {
|
|
1373
|
-
continue;
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
if (line.startsWith('-')) {
|
|
1377
|
-
original.push({
|
|
1378
|
-
lineNum: originalLineNum++,
|
|
1379
|
-
content: line.substring(1),
|
|
1380
|
-
type: 'removed'
|
|
1381
|
-
});
|
|
1382
|
-
} else if (line.startsWith('+')) {
|
|
1383
|
-
modified.push({
|
|
1384
|
-
lineNum: modifiedLineNum++,
|
|
1385
|
-
content: line.substring(1),
|
|
1386
|
-
type: 'added'
|
|
1387
|
-
});
|
|
1388
|
-
} else {
|
|
1389
|
-
// Context line
|
|
1390
|
-
const content = line.startsWith(' ') ? line.substring(1) : line;
|
|
1391
|
-
original.push({
|
|
1392
|
-
lineNum: originalLineNum++,
|
|
1393
|
-
content: content,
|
|
1394
|
-
type: 'context'
|
|
1395
|
-
});
|
|
1396
|
-
modified.push({
|
|
1397
|
-
lineNum: modifiedLineNum++,
|
|
1398
|
-
content: content,
|
|
1399
|
-
type: 'context'
|
|
1400
|
-
});
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
return { original, modified };
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
function renderDiffSide(lines, container, side) {
|
|
1408
|
-
container.innerHTML = lines.map(line => {
|
|
1409
|
-
let content = escapeHtml(line.content);
|
|
1410
|
-
|
|
1411
|
-
// Apply syntax highlighting if hljs is available
|
|
1412
|
-
if (window.hljs && line.content.trim() !== '') {
|
|
1413
|
-
try {
|
|
1414
|
-
const highlighted = hljs.highlightAuto(line.content);
|
|
1415
|
-
content = highlighted.value;
|
|
1416
|
-
} catch (e) {
|
|
1417
|
-
// Fall back to escaped HTML if highlighting fails
|
|
1418
|
-
content = escapeHtml(line.content);
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
|
-
return `
|
|
1423
|
-
<div class="diff-line diff-line-${line.type}">
|
|
1424
|
-
<div class="diff-line-number">${line.lineNum}</div>
|
|
1425
|
-
<div class="diff-line-content">${content}</div>
|
|
1426
|
-
</div>
|
|
1427
|
-
`;
|
|
1428
|
-
}).join('');
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
function escapeHtml(text) {
|
|
1432
|
-
const div = document.createElement('div');
|
|
1433
|
-
div.textContent = text;
|
|
1434
|
-
return div.innerHTML;
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1437
|
-
function showDiffError(error, overlay) {
|
|
1438
|
-
const content = overlay.querySelector('.diff-viewer-content');
|
|
1439
|
-
content.innerHTML = `
|
|
1440
|
-
<div style="padding: 40px; text-align: center; color: var(--text-secondary);">
|
|
1441
|
-
<p>Error loading diff:</p>
|
|
1442
|
-
<p style="color: #dc3545; margin-top: 8px;">${error}</p>
|
|
1443
|
-
</div>
|
|
1444
|
-
`;
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
// File operations (delete, rename)
|
|
1448
|
-
document.addEventListener('click', function(e) {
|
|
1449
|
-
if (e.target.closest('.delete-btn')) {
|
|
1450
|
-
const btn = e.target.closest('.delete-btn');
|
|
1451
|
-
const itemPath = btn.dataset.path;
|
|
1452
|
-
const itemName = btn.dataset.name;
|
|
1453
|
-
const isDirectory = btn.dataset.isDirectory === 'true';
|
|
1454
|
-
|
|
1455
|
-
const confirmMessage = `Are you sure you want to delete ${isDirectory ? 'folder' : 'file'} "${itemName}"?${isDirectory ? ' This will permanently delete the folder and all its contents.' : ''}`;
|
|
1456
|
-
|
|
1457
|
-
if (confirm(confirmMessage)) {
|
|
1458
|
-
btn.style.opacity = '0.5';
|
|
1459
|
-
|
|
1460
|
-
fetch('/api/delete', {
|
|
1461
|
-
method: 'POST',
|
|
1462
|
-
headers: {
|
|
1463
|
-
'Content-Type': 'application/json',
|
|
1464
|
-
},
|
|
1465
|
-
body: JSON.stringify({
|
|
1466
|
-
path: itemPath
|
|
1467
|
-
})
|
|
1468
|
-
})
|
|
1469
|
-
.then(response => {
|
|
1470
|
-
if (!response.ok) {
|
|
1471
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
1472
|
-
}
|
|
1473
|
-
return response.json();
|
|
1474
|
-
})
|
|
1475
|
-
.then(data => {
|
|
1476
|
-
if (data.success) {
|
|
1477
|
-
showNotification(`${isDirectory ? 'Folder' : 'File'} "${itemName}" deleted successfully`, 'success');
|
|
1478
|
-
setTimeout(() => window.location.reload(), 600);
|
|
1479
|
-
} else {
|
|
1480
|
-
btn.style.opacity = '1';
|
|
1481
|
-
showNotification('Failed to delete: ' + data.error, 'error');
|
|
1482
|
-
}
|
|
1483
|
-
})
|
|
1484
|
-
.catch(error => {
|
|
1485
|
-
console.error('Error deleting item:', error);
|
|
1486
|
-
btn.style.opacity = '1';
|
|
1487
|
-
let errorMessage = 'Failed to delete item';
|
|
1488
|
-
if (error.message.includes('HTTP 403')) {
|
|
1489
|
-
errorMessage = 'Access denied: Cannot delete this item';
|
|
1490
|
-
} else if (error.message.includes('HTTP 404')) {
|
|
1491
|
-
errorMessage = 'Item not found';
|
|
1492
|
-
} else if (error.message.includes('NetworkError') || error.message.includes('Failed to fetch')) {
|
|
1493
|
-
errorMessage = 'Network error: Please check your connection';
|
|
1494
|
-
}
|
|
1495
|
-
showNotification(errorMessage, 'error');
|
|
1496
|
-
});
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
|
|
1500
|
-
if (e.target.closest('.rename-btn')) {
|
|
1501
|
-
const btn = e.target.closest('.rename-btn');
|
|
1502
|
-
const itemPath = btn.dataset.path;
|
|
1503
|
-
const currentName = btn.dataset.name;
|
|
1504
|
-
const isDirectory = btn.dataset.isDirectory === 'true';
|
|
1505
|
-
|
|
1506
|
-
const newName = prompt(`Rename ${isDirectory ? 'folder' : 'file'}:`, currentName);
|
|
1507
|
-
if (newName && newName.trim() && newName !== currentName) {
|
|
1508
|
-
btn.style.opacity = '0.5';
|
|
1509
|
-
|
|
1510
|
-
fetch('/api/rename', {
|
|
1511
|
-
method: 'POST',
|
|
1512
|
-
headers: {
|
|
1513
|
-
'Content-Type': 'application/json',
|
|
1514
|
-
},
|
|
1515
|
-
body: JSON.stringify({
|
|
1516
|
-
path: itemPath,
|
|
1517
|
-
newName: newName.trim()
|
|
1518
|
-
})
|
|
1519
|
-
})
|
|
1520
|
-
.then(response => {
|
|
1521
|
-
if (!response.ok) {
|
|
1522
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
1523
|
-
}
|
|
1524
|
-
return response.json();
|
|
1525
|
-
})
|
|
1526
|
-
.then(data => {
|
|
1527
|
-
if (data.success) {
|
|
1528
|
-
showNotification(`${isDirectory ? 'Folder' : 'File'} renamed to "${newName.trim()}"`, 'success');
|
|
1529
|
-
setTimeout(() => window.location.reload(), 600);
|
|
1530
|
-
} else {
|
|
1531
|
-
btn.style.opacity = '1';
|
|
1532
|
-
showNotification('Failed to rename: ' + data.error, 'error');
|
|
1533
|
-
}
|
|
1534
|
-
})
|
|
1535
|
-
.catch(error => {
|
|
1536
|
-
console.error('Error renaming item:', error);
|
|
1537
|
-
btn.style.opacity = '1';
|
|
1538
|
-
let errorMessage = 'Failed to rename item';
|
|
1539
|
-
if (error.message.includes('HTTP 403')) {
|
|
1540
|
-
errorMessage = 'Access denied: Cannot rename this item';
|
|
1541
|
-
} else if (error.message.includes('HTTP 404')) {
|
|
1542
|
-
errorMessage = 'Item not found';
|
|
1543
|
-
} else if (error.message.includes('NetworkError') || error.message.includes('Failed to fetch')) {
|
|
1544
|
-
errorMessage = 'Network error: Please check your connection';
|
|
1545
|
-
}
|
|
1546
|
-
showNotification(errorMessage, 'error');
|
|
1547
|
-
});
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
});
|
|
1551
|
-
|
|
1552
|
-
// New file interface functionality
|
|
1553
|
-
const newFilenameInput = document.getElementById('new-filename-input');
|
|
1554
|
-
|
|
1555
|
-
// Update Monaco language when filename changes
|
|
1556
|
-
if (newFilenameInput) {
|
|
1557
|
-
newFilenameInput.addEventListener('input', function() {
|
|
1558
|
-
const filename = this.value.trim();
|
|
1559
|
-
if (monacoNewFileEditor && filename) {
|
|
1560
|
-
const language = getLanguageFromExtension(filename);
|
|
1561
|
-
const model = monacoNewFileEditor.getModel();
|
|
1562
|
-
if (model) {
|
|
1563
|
-
monaco.editor.setModelLanguage(model, language);
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
});
|
|
1567
|
-
}
|
|
1568
|
-
const createNewFileBtn = document.getElementById('create-new-file');
|
|
1569
|
-
const cancelNewFileBtn = document.getElementById('cancel-new-file');
|
|
1570
|
-
|
|
1571
|
-
if (createNewFileBtn) {
|
|
1572
|
-
createNewFileBtn.addEventListener('click', function() {
|
|
1573
|
-
const filename = newFilenameInput.value.trim();
|
|
1574
|
-
const content = monacoNewFileEditor ? monacoNewFileEditor.getValue() : '';
|
|
1575
|
-
|
|
1576
|
-
if (!filename) {
|
|
1577
|
-
showNotification('Please enter a filename', 'error');
|
|
1578
|
-
newFilenameInput.focus();
|
|
1579
|
-
return;
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
const currentPath = PathUtils.getCurrentPath();
|
|
1584
|
-
|
|
1585
|
-
fetch('/api/create-file', {
|
|
1586
|
-
method: 'POST',
|
|
1587
|
-
headers: {
|
|
1588
|
-
'Content-Type': 'application/json',
|
|
1589
|
-
},
|
|
1590
|
-
body: JSON.stringify({
|
|
1591
|
-
path: currentPath,
|
|
1592
|
-
filename: filename
|
|
1593
|
-
})
|
|
1594
|
-
})
|
|
1595
|
-
.then(response => {
|
|
1596
|
-
if (!response.ok) {
|
|
1597
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
1598
|
-
}
|
|
1599
|
-
return response.json();
|
|
1600
|
-
})
|
|
1601
|
-
.then(data => {
|
|
1602
|
-
if (data.success) {
|
|
1603
|
-
// If there's content, save it
|
|
1604
|
-
if (content.trim()) {
|
|
1605
|
-
const filePath = PathUtils.buildFilePath(currentPath, filename);
|
|
1606
|
-
return fetch('/api/save-file', {
|
|
1607
|
-
method: 'POST',
|
|
1608
|
-
headers: {
|
|
1609
|
-
'Content-Type': 'application/json',
|
|
1610
|
-
},
|
|
1611
|
-
body: JSON.stringify({
|
|
1612
|
-
path: filePath,
|
|
1613
|
-
content: content
|
|
1614
|
-
})
|
|
1615
|
-
});
|
|
1616
|
-
}
|
|
1617
|
-
return { json: () => Promise.resolve({ success: true }) };
|
|
1618
|
-
} else {
|
|
1619
|
-
throw new Error(data.error);
|
|
1620
|
-
}
|
|
1621
|
-
})
|
|
1622
|
-
.then(response => response.json ? response.json() : response)
|
|
1623
|
-
.then(data => {
|
|
1624
|
-
if (data.success) {
|
|
1625
|
-
showNotification(`File "${filename}" created successfully`, 'success');
|
|
1626
|
-
// Navigate back to the directory or to the new file
|
|
1627
|
-
const redirectPath = PathUtils.buildPathUrl('/', currentPath);
|
|
1628
|
-
setTimeout(() => window.location.href = redirectPath, 800);
|
|
1629
|
-
} else {
|
|
1630
|
-
throw new Error(data.error);
|
|
1631
|
-
}
|
|
1632
|
-
})
|
|
1633
|
-
.catch(error => {
|
|
1634
|
-
console.error('Error creating file:', error);
|
|
1635
|
-
let errorMessage = 'Failed to create file: ' + error.message;
|
|
1636
|
-
if (error.message.includes('HTTP 403')) {
|
|
1637
|
-
errorMessage = 'Access denied: Cannot create files in this directory';
|
|
1638
|
-
} else if (error.message.includes('HTTP 409') || error.message.includes('already exists')) {
|
|
1639
|
-
errorMessage = 'File already exists';
|
|
1640
|
-
} else if (error.message.includes('NetworkError') || error.message.includes('Failed to fetch')) {
|
|
1641
|
-
errorMessage = 'Network error: Please check your connection';
|
|
1642
|
-
}
|
|
1643
|
-
showNotification(errorMessage, 'error');
|
|
1644
|
-
});
|
|
1645
|
-
});
|
|
1646
|
-
}
|
|
1647
|
-
|
|
1648
|
-
if (cancelNewFileBtn) {
|
|
1649
|
-
cancelNewFileBtn.addEventListener('click', function() {
|
|
1650
|
-
const currentPath = PathUtils.getCurrentPath();
|
|
1651
|
-
const redirectPath = PathUtils.buildPathUrl('/', currentPath);
|
|
1652
|
-
window.location.href = redirectPath;
|
|
1653
|
-
});
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
async function copyToClipboard(text, button) {
|
|
1657
|
-
try {
|
|
1658
|
-
await navigator.clipboard.writeText(text);
|
|
1659
|
-
|
|
1660
|
-
// Show success feedback
|
|
1661
|
-
const originalIcon = button.innerHTML;
|
|
1662
|
-
const checkIcon = '<svg class="quick-icon" viewBox="0 0 16 16" width="16" height="16" fill="currentColor"><path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.75.75 0 0 1 1.06-1.06L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"></path></svg>';
|
|
1663
|
-
|
|
1664
|
-
button.innerHTML = checkIcon;
|
|
1665
|
-
button.style.color = '#28a745';
|
|
1666
|
-
|
|
1667
|
-
setTimeout(() => {
|
|
1668
|
-
button.innerHTML = originalIcon;
|
|
1669
|
-
button.style.color = '';
|
|
1670
|
-
}, 1000);
|
|
1671
|
-
} catch (err) {
|
|
1672
|
-
// Fallback for older browsers
|
|
1673
|
-
const textArea = document.createElement('textarea');
|
|
1674
|
-
textArea.value = text;
|
|
1675
|
-
textArea.style.position = 'fixed';
|
|
1676
|
-
textArea.style.left = '-999999px';
|
|
1677
|
-
textArea.style.top = '-999999px';
|
|
1678
|
-
document.body.appendChild(textArea);
|
|
1679
|
-
textArea.focus();
|
|
1680
|
-
textArea.select();
|
|
1681
|
-
|
|
1682
|
-
try {
|
|
1683
|
-
document.execCommand('copy');
|
|
1684
|
-
// Show success feedback (same as above)
|
|
1685
|
-
const originalIcon = button.innerHTML;
|
|
1686
|
-
const checkIcon = '<svg class="quick-icon" viewBox="0 0 16 16" width="16" height="16" fill="currentColor"><path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.75.75 0 0 1 1.06-1.06L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"></path></svg>';
|
|
1687
|
-
|
|
1688
|
-
button.innerHTML = checkIcon;
|
|
1689
|
-
button.style.color = '#28a745';
|
|
1690
|
-
|
|
1691
|
-
setTimeout(() => {
|
|
1692
|
-
button.innerHTML = originalIcon;
|
|
1693
|
-
button.style.color = '';
|
|
1694
|
-
}, 1000);
|
|
1695
|
-
} catch (fallbackErr) {
|
|
1696
|
-
console.error('Could not copy text: ', fallbackErr);
|
|
1697
|
-
}
|
|
1698
|
-
|
|
1699
|
-
document.body.removeChild(textArea);
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
});
|
|
1703
|
-
|
|
1704
|
-
// Simple commit modal functionality
|
|
1705
|
-
document.addEventListener('click', (e) => {
|
|
1706
|
-
if (e.target.matches('#commit-btn') || e.target.closest('#commit-btn')) {
|
|
1707
|
-
e.preventDefault();
|
|
1708
|
-
showCommitModal();
|
|
1709
|
-
}
|
|
1710
|
-
});
|
|
1711
|
-
|
|
1712
|
-
async function showCommitModal() {
|
|
1713
|
-
try {
|
|
1714
|
-
// Get current path from URL
|
|
1715
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
1716
|
-
const currentPath = urlParams.get('path') || '';
|
|
1717
|
-
|
|
1718
|
-
// Fetch git changes from current directory and subdirectories only
|
|
1719
|
-
const response = await fetch(`/api/git-status?currentPath=${encodeURIComponent(currentPath)}`);
|
|
1720
|
-
const data = await response.json();
|
|
1721
|
-
|
|
1722
|
-
if (!data.success) {
|
|
1723
|
-
showNotification('❌ Failed to load git changes', 'error');
|
|
1724
|
-
return;
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
const changedFiles = data.changes;
|
|
1728
|
-
|
|
1729
|
-
if (changedFiles.length === 0) {
|
|
1730
|
-
showNotification('ℹ️ No changes to commit', 'info');
|
|
1731
|
-
return;
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
showCommitModalWithFiles(changedFiles);
|
|
1735
|
-
} catch (error) {
|
|
1736
|
-
console.error('Error fetching git status:', error);
|
|
1737
|
-
showNotification('❌ Failed to load git changes', 'error');
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1741
|
-
function groupFilesByDirectory(files) {
|
|
1742
|
-
const groups = new Map();
|
|
1743
|
-
|
|
1744
|
-
files.forEach(file => {
|
|
1745
|
-
const parts = file.name.split('/');
|
|
1746
|
-
if (parts.length === 1) {
|
|
1747
|
-
// Root level file
|
|
1748
|
-
if (!groups.has('')) {
|
|
1749
|
-
groups.set('', { directory: null, files: [] });
|
|
1750
|
-
}
|
|
1751
|
-
groups.get('').files.push(file);
|
|
1752
|
-
} else {
|
|
1753
|
-
// File in subdirectory
|
|
1754
|
-
const directory = PathUtils.getDirectoryPath(file.name);
|
|
1755
|
-
if (!groups.has(directory)) {
|
|
1756
|
-
groups.set(directory, { directory, files: [] });
|
|
1757
|
-
}
|
|
1758
|
-
groups.get(directory).files.push(file);
|
|
1759
|
-
}
|
|
1760
|
-
});
|
|
1761
|
-
|
|
1762
|
-
// Convert to array and sort
|
|
1763
|
-
const result = Array.from(groups.values());
|
|
1764
|
-
result.sort((a, b) => {
|
|
1765
|
-
if (!a.directory && b.directory) return -1; // Root files first
|
|
1766
|
-
if (a.directory && !b.directory) return 1;
|
|
1767
|
-
if (!a.directory && !b.directory) return 0;
|
|
1768
|
-
return a.directory.localeCompare(b.directory);
|
|
1769
|
-
});
|
|
1770
|
-
|
|
1771
|
-
return result;
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
async function showCommitModalWithFiles(changedFiles) {
|
|
1775
|
-
// Group files by directory for better display
|
|
1776
|
-
const groupedFiles = groupFilesByDirectory(changedFiles);
|
|
1777
|
-
|
|
1778
|
-
// Get octicons for the modal
|
|
1779
|
-
const folderIcon = octicons.get('file-directory', { class: 'folder-icon' });
|
|
1780
|
-
|
|
1781
|
-
// Create modal
|
|
1782
|
-
const modal = document.createElement('div');
|
|
1783
|
-
modal.className = 'commit-modal-overlay';
|
|
1784
|
-
modal.innerHTML = `
|
|
1785
|
-
<div class="commit-modal">
|
|
1786
|
-
<div class="commit-modal-header">
|
|
1787
|
-
<h3>Commit Changes</h3>
|
|
1788
|
-
<button class="modal-close">×</button>
|
|
1789
|
-
</div>
|
|
1790
|
-
<div class="commit-modal-body">
|
|
1791
|
-
<div class="changed-files">
|
|
1792
|
-
<h4>Changed Files (${changedFiles.length})</h4>
|
|
1793
|
-
<ul class="file-list">
|
|
1794
|
-
${groupedFiles.map(group => `
|
|
1795
|
-
${group.directory ? `<li class="directory-group"><strong>${folderIcon} ${group.directory}/</strong></li>` : ''}
|
|
1796
|
-
${group.files.map(file => `
|
|
1797
|
-
<li class="file-item ${group.directory ? 'indented' : ''}">
|
|
1798
|
-
<label class="file-checkbox-label">
|
|
1799
|
-
<input type="checkbox" class="file-checkbox" data-file="${file.name}" checked>
|
|
1800
|
-
<span class="file-status">${file.status}</span>
|
|
1801
|
-
<span class="file-name">${group.directory ? file.name.split('/').pop() : file.name}</span>
|
|
1802
|
-
</label>
|
|
1803
|
-
</li>
|
|
1804
|
-
`).join('')}
|
|
1805
|
-
`).join('')}
|
|
1806
|
-
</ul>
|
|
1807
|
-
</div>
|
|
1808
|
-
<div class="commit-message-section">
|
|
1809
|
-
<textarea id="modal-commit-message" placeholder="Enter commit message..." rows="4"></textarea>
|
|
1810
|
-
</div>
|
|
1811
|
-
</div>
|
|
1812
|
-
<div class="commit-modal-footer">
|
|
1813
|
-
<button class="btn-cancel">Cancel</button>
|
|
1814
|
-
<button class="btn-commit" disabled>Commit Changes</button>
|
|
1815
|
-
</div>
|
|
1816
|
-
</div>
|
|
1817
|
-
`;
|
|
1818
|
-
|
|
1819
|
-
document.body.appendChild(modal);
|
|
1820
|
-
|
|
1821
|
-
// Handle modal interactions
|
|
1822
|
-
const messageInput = modal.querySelector('#modal-commit-message');
|
|
1823
|
-
const commitBtn = modal.querySelector('.btn-commit');
|
|
1824
|
-
const cancelBtn = modal.querySelector('.btn-cancel');
|
|
1825
|
-
const closeBtn = modal.querySelector('.modal-close');
|
|
1826
|
-
|
|
1827
|
-
// Update commit button based on message and selected files
|
|
1828
|
-
const updateCommitButton = () => {
|
|
1829
|
-
const hasMessage = messageInput.value.trim();
|
|
1830
|
-
const selectedFiles = modal.querySelectorAll('.file-checkbox:checked').length;
|
|
1831
|
-
commitBtn.disabled = !hasMessage || selectedFiles === 0;
|
|
1832
|
-
commitBtn.textContent = selectedFiles > 0
|
|
1833
|
-
? `Commit ${selectedFiles} file${selectedFiles === 1 ? '' : 's'}`
|
|
1834
|
-
: 'No files selected';
|
|
1835
|
-
};
|
|
1836
|
-
|
|
1837
|
-
messageInput.addEventListener('input', updateCommitButton);
|
|
1838
|
-
|
|
1839
|
-
// Handle checkbox changes
|
|
1840
|
-
modal.querySelectorAll('.file-checkbox').forEach(checkbox => {
|
|
1841
|
-
checkbox.addEventListener('change', updateCommitButton);
|
|
1842
|
-
});
|
|
1843
|
-
|
|
1844
|
-
// Initial button state
|
|
1845
|
-
updateCommitButton();
|
|
1846
|
-
|
|
1847
|
-
// Close modal handlers
|
|
1848
|
-
const closeModal = () => {
|
|
1849
|
-
document.body.removeChild(modal);
|
|
1850
|
-
};
|
|
1851
|
-
|
|
1852
|
-
cancelBtn.addEventListener('click', closeModal);
|
|
1853
|
-
closeBtn.addEventListener('click', closeModal);
|
|
1854
|
-
modal.addEventListener('click', (e) => {
|
|
1855
|
-
if (e.target === modal) closeModal();
|
|
1856
|
-
});
|
|
1857
|
-
|
|
1858
|
-
// Prevent keyboard shortcuts from interfering with the modal
|
|
1859
|
-
modal.addEventListener('keydown', (e) => {
|
|
1860
|
-
e.stopPropagation();
|
|
1861
|
-
});
|
|
1862
|
-
|
|
1863
|
-
// Commit handler
|
|
1864
|
-
commitBtn.addEventListener('click', async () => {
|
|
1865
|
-
const message = messageInput.value.trim();
|
|
1866
|
-
const selectedCheckboxes = modal.querySelectorAll('.file-checkbox:checked');
|
|
1867
|
-
const selectedFiles = Array.from(selectedCheckboxes).map(cb => cb.dataset.file);
|
|
1868
|
-
|
|
1869
|
-
if (!message || selectedFiles.length === 0) return;
|
|
1870
|
-
|
|
1871
|
-
const originalText = commitBtn.textContent;
|
|
1872
|
-
commitBtn.textContent = 'Committing...';
|
|
1873
|
-
commitBtn.disabled = true;
|
|
1874
|
-
|
|
1875
|
-
try {
|
|
1876
|
-
// Commit selected files
|
|
1877
|
-
const response = await fetch('/api/git-commit-selected', {
|
|
1878
|
-
method: 'POST',
|
|
1879
|
-
headers: { 'Content-Type': 'application/json' },
|
|
1880
|
-
body: JSON.stringify({ message, files: selectedFiles })
|
|
1881
|
-
});
|
|
1882
|
-
|
|
1883
|
-
if (response.ok) {
|
|
1884
|
-
showNotification(`✅ Successfully committed ${selectedFiles.length} file${selectedFiles.length === 1 ? '' : 's'}!`, 'success');
|
|
1885
|
-
closeModal();
|
|
1886
|
-
setTimeout(() => location.reload(), 1000);
|
|
1887
|
-
} else {
|
|
1888
|
-
const error = await response.text();
|
|
1889
|
-
showNotification(`❌ Commit failed: ${error}`, 'error');
|
|
1890
|
-
commitBtn.textContent = originalText;
|
|
1891
|
-
commitBtn.disabled = false;
|
|
1892
|
-
}
|
|
1893
|
-
} catch (err) {
|
|
1894
|
-
showNotification('❌ Commit failed', 'error');
|
|
1895
|
-
commitBtn.textContent = originalText;
|
|
1896
|
-
commitBtn.disabled = false;
|
|
1897
|
-
}
|
|
1898
|
-
});
|
|
1899
|
-
|
|
1900
|
-
// Focus the message input
|
|
1901
|
-
messageInput.focus();
|
|
1902
|
-
}
|