diff --git a/frontend/app.js b/frontend/app.js index 736451b..a0875f0 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -3301,7 +3301,7 @@ bodyEl.innerHTML = ""; var iframe = document.createElement("iframe"); iframe.id = "forge-iframe"; - iframe.src = "/editor-poc?vault=" + encodeURIComponent(data.vault) + "&path=" + encodeURIComponent(data.path); + iframe.src = "/editor-poc?vault=" + encodeURIComponent(data.vault) + "&path=" + encodeURIComponent(data.path) + "&_ts=" + Date.now(); iframe.style.cssText = "width:100%;height:82vh;border:none;display:block;"; bodyEl.appendChild(iframe); modal.classList.add("active"); diff --git a/frontend/editor-poc.html b/frontend/editor-poc.html index 72c96c6..cc07b7b 100644 --- a/frontend/editor-poc.html +++ b/frontend/editor-poc.html @@ -784,6 +784,13 @@ body { font-family: var(--sans); background: var(--bg); color: var(--text); heig function getVisibleSlash() { return slashItems.filter(function(i) { return i.style.display !== 'none'; }); } function selectSlashAction(action) { + // Clean up the /command text from the current line + var line = getLine(); + var m = line.text.match(/^\/\S*\s*/); + if (m) { + ta.value = val().substring(0, line.start) + val().substring(line.start + m[0].length); + setPos(line.start); + } hideSlash(); // Handle QI-specific actions if (action && action.indexOf('mermaid-') === 0) { diff --git a/frontend/js/viewer.js b/frontend/js/viewer.js index 10995a3..3e01b1f 100644 --- a/frontend/js/viewer.js +++ b/frontend/js/viewer.js @@ -9,6 +9,7 @@ import { initDashboardTabs } from './sync.js'; import { renderMermaidBlocks } from './mermaid-viewer.js'; import { DashboardStatsWidget, DashboardRecentWidget, DashboardBookmarkWidget, DashboardSharedWidget, DashboardConflictsWidget } from './dashboard.js'; import { openShareDialog } from './config.js'; +import { cacheViewedFile, getCachedFile } from './offline.js'; // --------------------------------------------------------------------------- // Outline/TOC Manager // --------------------------------------------------------------------------- @@ -336,9 +337,32 @@ export async function openFile(vaultName, filePath) { try { const url = `/api/file/${encodeURIComponent(vaultName)}?path=${encodeURIComponent(filePath)}`; const data = await api(url); + // Cache the file for offline use + if (data && !data.unsupported && data.content) { + cacheViewedFile(vaultName, filePath, data.content, data.modified); + } renderFile(data); } catch (err) { - area.innerHTML = '

Impossible de charger le fichier.

'; + // Try IndexedDB fallback + console.log('[Viewer] Network failed, trying offline cache:', err); + const cached = await getCachedFile(vaultName, filePath); + if (cached && cached.content) { + const fakeData = { + vault: vaultName, + path: filePath, + title: filePath.split('/').pop().replace(/\.md$/, ''), + content: cached.content, + html: null, + raw_size: cached.content.length, + modified: cached.modified || '', + tags: [], + offline: true + }; + renderFile(fakeData); + showToast('Fichier charge depuis le cache hors-ligne', 'info'); + } else { + area.innerHTML = '

Impossible de charger le fichier — vous etes hors-ligne et ce fichier n\'est pas en cache.

'; + } } } @@ -507,7 +531,7 @@ export function renderFile(data) { bodyEl.style.overflow = "hidden"; var iframe = document.createElement("iframe"); iframe.id = "forge-iframe"; - iframe.src = "/editor-poc?vault=" + encodeURIComponent(data.vault) + "&path=" + encodeURIComponent(data.path); + iframe.src = "/editor-poc?vault=" + encodeURIComponent(data.vault) + "&path=" + encodeURIComponent(data.path) + "&_ts=" + Date.now(); iframe.style.cssText = "width:100%;height:82vh;border:none;display:block;"; bodyEl.appendChild(iframe); modal.classList.add("active");