Skip to content

Commit 2973549

Browse files
committed
Enhance file selection logic in WorkspaceManager and update navbar with GitHub link. Auto-select first file if available when no file is selected, and clear editor when no files exist. Improve quick actions to focus on the first file or clear the editor accordingly.
1 parent f81b149 commit 2973549

File tree

3 files changed

+70
-27
lines changed

3 files changed

+70
-27
lines changed

app/static/js/workspace_manager.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,30 @@ class WorkspaceManager {
289289

290290
// Update editor
291291
if (this.currentState.selectedFile && this.currentState.files[this.currentState.selectedFile]) {
292+
// Selected file exists - load it
292293
if (window.openFile) {
293294
window.openFile(this.currentState.selectedFile);
294295
}
295296
} else {
296-
if (window.workspaceMonacoEditor) {
297-
window.workspaceMonacoEditor.setValue('Select a file from the left to view its content.');
298-
}
299-
if (window.updateFilePathLabel) {
300-
window.updateFilePathLabel(null);
297+
// No selected file - check if we have any files to auto-select
298+
const fileKeys = Object.keys(this.currentState.files);
299+
if (fileKeys.length > 0 && !this.currentState.selectedFile) {
300+
// Auto-select first file
301+
const firstFile = fileKeys[0];
302+
this.currentState.selectedFile = firstFile;
303+
this.saveState(this.currentContextId);
304+
305+
if (window.openFile) {
306+
window.openFile(firstFile);
307+
}
308+
} else {
309+
// No files available - show placeholder
310+
if (window.workspaceMonacoEditor) {
311+
window.workspaceMonacoEditor.setValue('Select a file from the left to view its content.');
312+
}
313+
if (window.updateFilePathLabel) {
314+
window.updateFilePathLabel(null);
315+
}
301316
}
302317
}
303318

app/templates/components/navbar.html

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ <h1 class="text-xl font-black tracking-tight">
99
</h1>
1010
</div>
1111
<nav class="flex items-center gap-6">
12-
<button class="bg-white text-black border-2 border-black shadow-[2px_2px_0px_0px_rgba(0,0,0,1)] font-semibold hover:shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] hover:translate-x-[-2px] hover:translate-y-[-2px] active:shadow-[1px_1px_0px_0px_rgba(0,0,0,1)] active:translate-x-[1px] active:translate-y-[1px] transition-all px-3 py-1.5 flex items-center gap-2 text-sm">
13-
<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24">
14-
<path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/>
15-
</svg>
16-
GitHub
17-
</button>
18-
</nav>
12+
<a
13+
href="https://github.com/coderamp-labs/gitrules"
14+
target="_blank"
15+
rel="noopener noreferrer"
16+
class="bg-white text-black border-2 border-black shadow-[2px_2px_0px_0px_rgba(0,0,0,1)] font-semibold hover:shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] hover:translate-x-[-2px] hover:translate-y-[-2px] active:shadow-[1px_1px_0px_0px_rgba(0,0,0,1)] active:translate-x-[1px] active:translate-y-[1px] transition-all px-3 py-1.5 flex items-center gap-2 text-sm"
17+
>
18+
<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
19+
<path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/>
20+
</svg>
21+
GitHub
22+
</a>
23+
</nav>
24+
1925
</div>
2026
</div>
2127
</header>

app/templates/components/quick_actions.html

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -451,24 +451,46 @@ <h3 class="text-sm font-black text-black mb-2 flex items-center gap-1">
451451

452452
// Clear editor and set focus when workspace appears
453453
function clearEditorAndFocus() {
454-
// Clear selected file in workspace manager
454+
// Auto-focus first file if available, otherwise clear editor
455455
if (window.workspaceManager && window.workspaceManager.currentState) {
456-
window.workspaceManager.currentState.selectedFile = null;
457-
window.workspaceManager.saveState(window.workspaceManager.currentContextId);
458-
}
459-
460-
// Clear and focus the monaco editor
461-
if (window.workspaceMonacoEditor) {
462-
window.workspaceMonacoEditor.setValue('');
463-
window.workspaceMonacoEditor.focus();
464-
}
465-
466-
// Update file path label to show no file selected
467-
if (window.updateFilePathLabel) {
468-
window.updateFilePathLabel(null);
456+
const state = window.workspaceManager.currentState;
457+
const fileKeys = Object.keys(state.files);
458+
459+
if (fileKeys.length > 0) {
460+
// Auto-select the first file
461+
const firstFile = fileKeys[0];
462+
state.selectedFile = firstFile;
463+
window.workspaceManager.saveState(window.workspaceManager.currentContextId);
464+
465+
// Load the first file in editor
466+
if (window.workspaceMonacoEditor && state.files[firstFile]) {
467+
window.workspaceMonacoEditor.setValue(state.files[firstFile]);
468+
window.workspaceMonacoEditor.focus();
469+
}
470+
471+
// Update file path label
472+
if (window.updateFilePathLabel) {
473+
window.updateFilePathLabel(firstFile);
474+
}
475+
} else {
476+
// No files available - clear everything
477+
state.selectedFile = null;
478+
window.workspaceManager.saveState(window.workspaceManager.currentContextId);
479+
480+
// Clear and focus the monaco editor
481+
if (window.workspaceMonacoEditor) {
482+
window.workspaceMonacoEditor.setValue('');
483+
window.workspaceMonacoEditor.focus();
484+
}
485+
486+
// Update file path label to show no file selected
487+
if (window.updateFilePathLabel) {
488+
window.updateFilePathLabel(null);
489+
}
490+
}
469491
}
470492

471-
// Re-render file tree to clear selection
493+
// Re-render file tree to show selection
472494
if (window.renderFileTree) {
473495
window.renderFileTree();
474496
}

0 commit comments

Comments
 (0)