From c538717d362b5bcd554c7c44b84da4693cd8cf6a Mon Sep 17 00:00:00 2001 From: Alex Hernandez Date: Fri, 6 Mar 2026 20:23:51 +1000 Subject: [PATCH] :bug: fix tooltip hover --- .../components/Editor/MarkdownEditor.tsx | 2 ++ .../components/FileTree/FileTreeNode.tsx | 1 + src/renderer/store/editorStore.ts | 21 ++++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/renderer/components/Editor/MarkdownEditor.tsx b/src/renderer/components/Editor/MarkdownEditor.tsx index 13d588b..8abb33e 100644 --- a/src/renderer/components/Editor/MarkdownEditor.tsx +++ b/src/renderer/components/Editor/MarkdownEditor.tsx @@ -213,6 +213,7 @@ const annotationHoverTooltip = hoverTooltip( create() { const dom = document.createElement('div') dom.className = 'annotation-tooltip' + dom.addEventListener('mousemove', (e) => e.stopPropagation()) const label = document.createElement('span') label.className = 'annotation-tooltip-label' label.textContent = 'Your comment' @@ -243,6 +244,7 @@ const annotationHoverTooltip = hoverTooltip( create() { const dom = document.createElement('div') dom.className = 'annotation-tooltip' + dom.addEventListener('mousemove', (e) => e.stopPropagation()) const label = document.createElement('span') label.className = 'annotation-tooltip-label' diff --git a/src/renderer/components/FileTree/FileTreeNode.tsx b/src/renderer/components/FileTree/FileTreeNode.tsx index 1055a3a..9abf564 100644 --- a/src/renderer/components/FileTree/FileTreeNode.tsx +++ b/src/renderer/components/FileTree/FileTreeNode.tsx @@ -30,6 +30,7 @@ export function FileTreeNode({ node, depth, dirPath, siblings }: Props): JSX.Ele const openFile = async (): Promise => { if (node.type === 'file') { + if (node.path === activeFilePath) return const content = await window.api.readFile(node.path) setActiveFile(node.path, content) } diff --git a/src/renderer/store/editorStore.ts b/src/renderer/store/editorStore.ts index 5a02c1a..60adfd4 100644 --- a/src/renderer/store/editorStore.ts +++ b/src/renderer/store/editorStore.ts @@ -109,6 +109,19 @@ function scheduleSave(getData: () => Record): void { }, 1500) } +// Debounced auto-save — writes the active file to disk 10s after the user stops typing, +// protecting against content loss if the renderer crashes while the editor is idle. +let _autoSaveTimer: ReturnType | null = null +function scheduleAutoSave(getData: () => { path: string; content: string } | null): void { + if (_autoSaveTimer) clearTimeout(_autoSaveTimer) + _autoSaveTimer = setTimeout(() => { + const d = getData() + if (!d) return + const api = (window as unknown as { api?: { writeFile: (p: string, c: string) => Promise } }).api + api?.writeFile(d.path, d.content).catch(console.error) + }, 10_000) +} + export const useEditorStore = create((set, get) => ({ fileTree: [], setFileTree: (fileTree) => set({ fileTree }), @@ -175,7 +188,13 @@ export const useEditorStore = create((set, get) => ({ } }) }, - setContent: (content) => set({ activeFileContent: content, isDirty: true }), + setContent: (content) => { + set({ activeFileContent: content, isDirty: true }) + scheduleAutoSave(() => { + const { activeFilePath, activeFileContent } = get() + return activeFilePath ? { path: activeFilePath, content: activeFileContent } : null + }) + }, markSaved: () => set({ isDirty: false }), chatSessionsByFile: {},