diff --git a/src/renderer/plugins/markdown-link.ts b/src/renderer/plugins/markdown-link.ts index e321ce39..6a1dac5a 100644 --- a/src/renderer/plugins/markdown-link.ts +++ b/src/renderer/plugins/markdown-link.ts @@ -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) => { diff --git a/src/renderer/services/document.ts b/src/renderer/services/document.ts index 19ad4b8e..748087a6 100644 --- a/src/renderer/services/document.ts +++ b/src/renderer/services/document.ts @@ -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 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 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)