Skip to content

Commit 9fc5dd2

Browse files
committed
fix sync of editor state after typing
1 parent ec7e606 commit 9fc5dd2

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

app/static/js/auto_share.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ class AutoShareManager {
3030

3131
// Listen for workspace changes
3232
this.attachListeners();
33+
34+
// Trigger initial sync if there's content
35+
setTimeout(() => {
36+
const data = this.collectWorkspaceData();
37+
if (Object.keys(data).length > 0) {
38+
this.markDirty();
39+
}
40+
}, 500);
3341
}
3442

3543
attachListeners() {
@@ -72,6 +80,16 @@ class AutoShareManager {
7280
// Collect current workspace data
7381
const payload = this.collectWorkspaceData();
7482

83+
// If no files, don't sync
84+
if (Object.keys(payload).length === 0) {
85+
this.dirty = false;
86+
this.setState('synced');
87+
if (this.linkInput) {
88+
this.linkInput.value = 'Add files to generate install link';
89+
}
90+
return;
91+
}
92+
7593
// Check if payload has changed
7694
const payloadHash = this.hashPayload(payload);
7795
if (payloadHash === this.lastPayloadHash) {
@@ -166,13 +184,17 @@ class AutoShareManager {
166184
case 'synced':
167185
if (this.panel) this.panel.style.display = 'flex';
168186
if (this.linkInput) {
169-
this.linkInput.value = this.currentShareUrl || 'No share link yet';
187+
this.linkInput.value = this.currentShareUrl || 'Add files to generate install link';
170188
this.linkInput.classList.remove('opacity-50');
171189
this.linkInput.disabled = false;
172190
}
173191
if (this.copyButton) {
174-
this.copyButton.disabled = false;
175-
this.copyButton.classList.remove('opacity-50');
192+
this.copyButton.disabled = !this.currentShareUrl;
193+
if (this.currentShareUrl) {
194+
this.copyButton.classList.remove('opacity-50');
195+
} else {
196+
this.copyButton.classList.add('opacity-50');
197+
}
176198
}
177199
break;
178200

app/static/js/monaco_editor.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ function initializeWorkspaceEditor() {
2626
if (state && state.selectedFile) {
2727
// Update the file content in workspace state
2828
state.files[state.selectedFile] = workspaceMonacoEditor.getValue();
29+
// Save to localStorage
30+
if (window.workspaceManager) {
31+
window.workspaceManager.saveState(window.workspaceManager.currentContextId);
32+
}
2933
// Dispatch event for auto-share
3034
window.dispatchEvent(new CustomEvent('workspace-content-changed'));
3135
}

0 commit comments

Comments
 (0)