From ecd7e57c2edcb9cea91de5094159a6c4956f3290 Mon Sep 17 00:00:00 2001 From: Antigravity Date: Sun, 24 May 2026 21:37:09 +0000 Subject: [PATCH] fix(editor): save-on-close & correct image tracking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Auto-sauvegarde à la fermeture de l'éditeur fullPage si isDirty (évite que la vignette reste après suppression d'image sans Ctrl+S) - Correction de resolveImagesForSave : fusion des images contenu HTML + images standalone (hors éditeur) en excluant les removedImageUrls, pour ne pas perdre les images uploadées séparément à la sauvegarde --- .../note-editor/note-editor-context.tsx | 30 ++++++++++++------- .../note-editor/note-editor-toolbar.tsx | 9 +++++- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/memento-note/components/note-editor/note-editor-context.tsx b/memento-note/components/note-editor/note-editor-context.tsx index ddc109c..10a20ba 100644 --- a/memento-note/components/note-editor/note-editor-context.tsx +++ b/memento-note/components/note-editor/note-editor-context.tsx @@ -313,19 +313,27 @@ export function NoteEditorProvider({ note, readOnly = false, fullPage = false, o }, [content, isMarkdown]) const resolveImagesForSave = useCallback((contentToSave: string): string[] => { - if (!contentToSave) return [] - if (!isMarkdown) { - return extractImagesFromHTML(contentToSave) - } else { - const urls = new Set() - const matches = contentToSave.matchAll(/!\[.*?\]\((.*?)\)/g) - for (const match of matches) { - const src = match[1]?.trim() - if (src) urls.add(src) + // Images présentes dans le contenu de l'éditeur (inline dans le HTML ou Markdown) + let contentImages: string[] = [] + if (contentToSave) { + if (!isMarkdown) { + contentImages = extractImagesFromHTML(contentToSave) + } else { + const urls = new Set() + const matches = contentToSave.matchAll(/!\[.*?\]\((.*?)\)/g) + for (const match of matches) { + const src = match[1]?.trim() + if (src) urls.add(src) + } + contentImages = Array.from(urls) } - return Array.from(urls) } - }, [isMarkdown]) + // Images "standalone" uploadées séparément (hors contenu éditeur), non supprimées + const standaloneImages = images.filter(url => !removedImageUrls.includes(url) && !contentImages.includes(url)) + // Fusion dédupliquée : images du contenu + images standalone conservées + return Array.from(new Set([...contentImages, ...standaloneImages])) + }, [isMarkdown, images, removedImageUrls]) + const handleGenerateTitles = async () => { const fullContentForAI = [ diff --git a/memento-note/components/note-editor/note-editor-toolbar.tsx b/memento-note/components/note-editor/note-editor-toolbar.tsx index e7d10a4..0d776ec 100644 --- a/memento-note/components/note-editor/note-editor-toolbar.tsx +++ b/memento-note/components/note-editor/note-editor-toolbar.tsx @@ -91,10 +91,17 @@ export function NoteEditorToolbar({ mode, onClose, onToggleAttachments, attachme } if (mode === 'fullPage') { + const handleCloseWithSave = async () => { + if (state.isDirty && !state.isSaving) { + await actions.handleSaveInPlace() + } + onClose() + } + return (