From c29ed4438927c732a93b160777f0b4d3616307e6 Mon Sep 17 00:00:00 2001 From: purocean Date: Wed, 3 Jul 2024 22:39:40 +0800 Subject: [PATCH] refactor: fix history-stack plugin switching issue --- src/renderer/plugins/history-stack.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/renderer/plugins/history-stack.ts b/src/renderer/plugins/history-stack.ts index aea397f9..1ec11b7d 100644 --- a/src/renderer/plugins/history-stack.ts +++ b/src/renderer/plugins/history-stack.ts @@ -29,15 +29,18 @@ export default { const nextState = stack[index] - ctx.doc.switchDoc(nextState.doc, { source: 'history-stack', position: nextState.position }) - - idx = index - refresh() + ctx.doc.switchDoc(nextState.doc, { source: 'history-stack', position: nextState.position }).then(() => { + idx = index + refresh() + }) } function removeFromStack (doc?: PathItem) { stack = stack.filter(x => !ctx.doc.isSubOrSameFile(doc, x.doc)) - idx = stack.length - 1 + if (idx >= stack.length) { + idx = stack.length - 1 + } + refresh() } @@ -117,6 +120,7 @@ export default { ctx.registerHook('DOC_DELETED', ({ doc }) => removeFromStack(doc)) ctx.registerHook('DOC_MOVED', ({ oldDoc }) => removeFromStack(oldDoc)) + ctx.registerHook('DOC_SWITCH_FAILED', ({ doc }) => { doc && removeFromStack(doc) }) ctx.action.registerAction({ name: backId,