diff --git a/frontend/js/ai.js b/frontend/js/ai.js index 6d6835a..7b5f2c5 100644 --- a/frontend/js/ai.js +++ b/frontend/js/ai.js @@ -57,9 +57,9 @@ function replaceSelection(editorView, newText, mode = 'replace') { // ── Show toast notification ── function showToast(msg, type = 'info') { - // Use the global showToast if available (from ui.js) - if (typeof window._showToast === 'function') { - window._showToast(msg, type); + // Use global showToast if available, otherwise console + if (typeof window._obsigateShowToast === 'function') { + window._obsigateShowToast(msg, type); } } @@ -357,6 +357,3 @@ function createSeparator() { sep.style.cssText = 'width:1px;height:16px;background:var(--border-color);margin:0 2px'; return sep; } - -// Export showToast for the module -export function setToast(fn) { window._showToast = fn; } diff --git a/frontend/js/app.js b/frontend/js/app.js index 4ad5e30..18bf117 100644 --- a/frontend/js/app.js +++ b/frontend/js/app.js @@ -3,10 +3,13 @@ All code lives in frontend/js/*.js modules. */ import * as UI from './ui.js'; +import * as Utils from './utils.js'; + +// Wire up AI toolbar toast (avoids circular import in utils.js) +window._obsigateShowToast = UI.showToast; import * as Sidebar from './sidebar.js'; import * as Auth from './auth.js'; import * as Viewer from './viewer.js'; -import * as Utils from './utils.js'; import * as Sync from './sync.js'; import { initGraphView } from './graph.js'; import * as Legacy from './legacy.js'; diff --git a/frontend/js/utils.js b/frontend/js/utils.js index ce21c86..afdbc8c 100644 --- a/frontend/js/utils.js +++ b/frontend/js/utils.js @@ -2,10 +2,7 @@ import { state } from './state.js'; import { api } from './auth.js'; import { openFile, showWelcome } from './viewer.js'; import { refreshSidebarForContext, refreshTagsForContext } from './sidebar.js'; -import { createAIToolbar, setToast } from './ai.js'; -import { showToast } from './ui.js'; - -let _aiToolbarCreated = false; +import { createAIToolbar } from './ai.js'; // --------------------------------------------------------------------------- // File extension → Lucide icon mapping @@ -367,16 +364,6 @@ async function openEditor(vaultName, filePath) { state: cmState, parent: bodyEl, }); - - // Set up AI toolbar (once) - if (!_aiToolbarCreated) { - setToast(showToast); - const container = document.getElementById('ai-toolbar-container'); - if (container) { - createAIToolbar(container, () => state.editorView); - _aiToolbarCreated = true; - } - } } catch (err) { console.error("CodeMirror init failed, falling back to textarea:", err); state.fallbackEditorEl = document.createElement("textarea"); @@ -385,6 +372,12 @@ async function openEditor(vaultName, filePath) { bodyEl.appendChild(state.fallbackEditorEl); } + // Set up AI toolbar (recreate each time editor opens) + const container = document.getElementById('ai-toolbar-container'); + if (container && !container.querySelector('.ai-toolbar')) { + createAIToolbar(container, () => state.editorView || null); + } + modal.classList.add("active"); safeCreateIcons(); }