From c3638d689a862a8d09c5feb8fdea21c9c02e6d37 Mon Sep 17 00:00:00 2001 From: purocean Date: Sat, 11 Jul 2026 17:41:18 +0800 Subject: [PATCH] refactor: always show floating editor hint --- src/renderer/plugins/__tests__/floating-editor.ts | 5 +++-- src/renderer/plugins/__tests__/markdown-extra-2.ts | 5 ++--- src/renderer/plugins/floating-editor.ts | 13 +------------ 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/renderer/plugins/__tests__/floating-editor.ts b/src/renderer/plugins/__tests__/floating-editor.ts index fbccbe76..786d88ea 100644 --- a/src/renderer/plugins/__tests__/floating-editor.ts +++ b/src/renderer/plugins/__tests__/floating-editor.ts @@ -211,7 +211,7 @@ describe('floating-editor plugin', () => { expect(ctx.editorInstance.focus).toHaveBeenCalledTimes(1) }) - test('watcher shows a limited preview hint when floating editor is available', () => { + test('watcher shows a preview hint whenever floating editor is available', () => { const ctx = createCtx() floatingEditor.register(ctx) const canShow = ctx.lib.vue.watch.mock.calls[0][0] @@ -222,7 +222,8 @@ describe('floating-editor plugin', () => { const hint = document.body.querySelector('.floating-editor-hint') as HTMLElement expect(hint.textContent).toBe('floating-editor.preview-hint:Alt') - expect(ctx.storage.set).toHaveBeenCalledWith('plugin.floating-editor.preview-hint-count', 1) + expect(ctx.storage.get).not.toHaveBeenCalled() + expect(ctx.storage.set).not.toHaveBeenCalled() }) test('titlebar and resize handles move, maximize, restore, and close the floating frame', async () => { diff --git a/src/renderer/plugins/__tests__/markdown-extra-2.ts b/src/renderer/plugins/__tests__/markdown-extra-2.ts index b14c730e..519a942e 100644 --- a/src/renderer/plugins/__tests__/markdown-extra-2.ts +++ b/src/renderer/plugins/__tests__/markdown-extra-2.ts @@ -544,7 +544,7 @@ describe('markdown extra branch coverage', () => { expect(mocks.replaceLine).not.toHaveBeenCalled() }) - test('floating editor noops when unavailable and suppresses hints after the display limit', async () => { + test('floating editor noops when unavailable and shows hints once available', async () => { vi.useFakeTimers() vi.spyOn(window, 'requestAnimationFrame').mockImplementation((fn: FrameRequestCallback) => { fn(0) @@ -552,7 +552,6 @@ describe('markdown extra branch coverage', () => { }) const ctx = createFloatingCtx() ctx.store.state.showEditor = true - ctx.storage.get.mockReturnValue(5) floatingEditor.register(ctx) await ctx.actions.get('layout.show-floating-editor').handler({ line: 2, clientY: 80 }) @@ -563,6 +562,6 @@ describe('markdown extra branch coverage', () => { expect(canShow()).toBe(false) ctx.store.state.showEditor = false onChange(true) - expect(document.body.querySelector('.floating-editor-hint')).toBeNull() + expect(document.body.querySelector('.floating-editor-hint')).toBeTruthy() }) }) diff --git a/src/renderer/plugins/floating-editor.ts b/src/renderer/plugins/floating-editor.ts index f2057db6..90a96629 100644 --- a/src/renderer/plugins/floating-editor.ts +++ b/src/renderer/plugins/floating-editor.ts @@ -21,8 +21,6 @@ const DEFAULT_HEIGHT = MIN_HEIGHT const REVEAL_TOP_CONTEXT_LINES = 3 const SIDE_MARGIN = 24 const SCREEN_MARGIN = 8 -const HINT_STORAGE_KEY = 'plugin.floating-editor.preview-hint-count' -const HINT_LIMIT = 5 const HINT_DURATION = 5000 const EDITOR_SCROLL_SYNC_PAUSE_TIMEOUT = 350 const CLOSE_SYNC_PAUSE_TIMEOUT = 800 @@ -272,14 +270,6 @@ export default { editorDom.style.height = `${Math.round(height)}px` } - function getHintCount () { - return ctx.storage.get(HINT_STORAGE_KEY, 0) - } - - function setHintCount (count: number) { - ctx.storage.set(HINT_STORAGE_KEY, count) - } - function hideHint () { if (hintTimer) { clearTimeout(hintTimer) @@ -305,7 +295,7 @@ export default { } function showHint () { - if (visible || hint || getHintCount() >= HINT_LIMIT) { + if (visible || hint) { return } @@ -319,7 +309,6 @@ export default { hint.textContent = getHintText() document.body.appendChild(hint) positionHint() - setHintCount(getHintCount() + 1) hintTimer = window.setTimeout(hideHint, HINT_DURATION) }