upd: 优化文件变动处理

This commit is contained in:
purocean
2021-08-10 19:31:01 +08:00
parent d182572fed
commit b8db21e4ea
2 changed files with 12 additions and 1 deletions
+2 -1
View File
@@ -96,9 +96,10 @@ export default defineComponent({
}
}
function handleMoved (payload?: { oldDoc: Doc }) {
function handleMoved (payload?: { oldDoc: Doc, newDoc: Doc }) {
if (payload) {
removeFile(payload.oldDoc)
switchFile(payload.newDoc)
}
}
@@ -51,6 +51,13 @@ export default {
})
}
function removeFromStack (doc?: Doc) {
const newStack = stack.filter(x => ctx.doc.toUri(doc) !== ctx.doc.toUri(x))
stack.splice(0, stack.length)
stack.push(...newStack)
updateMenu()
}
ctx.bus.on('doc.switched', (file?: Doc) => {
if (file) {
if (!ctx.doc.isSameFile(stack[idx], file)) {
@@ -62,6 +69,9 @@ export default {
updateMenu()
})
ctx.bus.on('doc.deleted', removeFromStack)
ctx.bus.on('doc.moved', ({ oldDoc }) => removeFromStack(oldDoc))
ctx.action.registerAction({
name: backId,
handler: () => go(-1),