fix: AI toolbar créée hors try/catch + simplifié imports circulaires
CI / lint (push) Failing after 4s
CI / test (push) Has been skipped
CI / build (push) Has been skipped
CI / security (push) Successful in 8s

This commit is contained in:
2026-05-30 17:48:11 -04:00
parent b76fc64325
commit 281636efa0
3 changed files with 14 additions and 21 deletions
+7 -14
View File
@@ -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();
}