mirror of
https://github.com/purocean/yn.git
synced 2026-09-24 15:46:02 +08:00
refactor: update document switching logic and position handling
This commit is contained in:
@@ -344,6 +344,18 @@ export default {
|
||||
})
|
||||
})
|
||||
|
||||
ctx.registerHook('DOC_SWITCH_SKIPPED', ({ opts }) => {
|
||||
if (opts?.position) {
|
||||
ctx.routines.changePosition(opts.position)
|
||||
}
|
||||
})
|
||||
|
||||
ctx.registerHook('DOC_SWITCHED', ({ doc, opts }) => {
|
||||
if (doc && opts?.position) {
|
||||
ctx.routines.changePosition(opts.position)
|
||||
}
|
||||
})
|
||||
|
||||
ctx.markdown.registerPlugin(md => {
|
||||
md.core.ruler.push('convert_relative_path', convertLink)
|
||||
md.renderer.rules.link_open = (tokens, idx, options, _, slf) => {
|
||||
|
||||
@@ -20,7 +20,6 @@ import { isWindows } from '@fe/support/env'
|
||||
import { getAllRepos, getRepo, inputPassword, openPath, showItemInFolder } from './base'
|
||||
import { t } from './i18n'
|
||||
import { getSetting, setSetting } from './setting'
|
||||
import { changePosition } from './routines'
|
||||
|
||||
const logger = getLogger('document')
|
||||
const lock = new AsyncLock()
|
||||
@@ -626,10 +625,6 @@ async function _switchDoc (doc: Doc | null, opts?: SwitchDocOpts): Promise<void>
|
||||
if (!force && store.state.currentFile !== undefined && isSameFile(doc, store.state.currentFile)) {
|
||||
logger.debug('skip switch', doc)
|
||||
triggerHook('DOC_SWITCH_SKIPPED', { doc, opts })
|
||||
|
||||
if (opts?.position) {
|
||||
changePosition(opts.position)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -693,10 +688,6 @@ async function _switchDoc (doc: Doc | null, opts?: SwitchDocOpts): Promise<void>
|
||||
|
||||
store.state.currentContent = content
|
||||
triggerHook('DOC_SWITCHED', { doc: store.state.currentFile || null, opts })
|
||||
|
||||
if (opts?.position) {
|
||||
changePosition(opts.position)
|
||||
}
|
||||
} catch (error: any) {
|
||||
triggerHook('DOC_SWITCH_FAILED', { doc, message: error.message, opts })
|
||||
useToast().show('warning', error.message.includes('Malformed') ? t('document.wrong-password') : error.message)
|
||||
|
||||
Reference in New Issue
Block a user