mirror of
https://github.com/purocean/yn.git
synced 2026-08-29 01:21:05 +08:00
refactor: always show floating editor hint
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user