From 6be431b9d61d98d5194e7e4ba0d9fa8061d9ccba Mon Sep 17 00:00:00 2001 From: Richard Yu Date: Sat, 7 May 2022 10:13:01 +0800 Subject: [PATCH] fix: context menu command not work --- CHANGELOG.md | 3 +++ src/operations/moveTo.ts | 5 ++++- src/stores/target.ts | 13 ++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08b9dc7..30e53bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v0.0.12 + +- fix: try to fix context menu command not work ## v0.0.11 - fix: try to fix console error. diff --git a/src/operations/moveTo.ts b/src/operations/moveTo.ts index 35418bc..180f40a 100644 --- a/src/operations/moveTo.ts +++ b/src/operations/moveTo.ts @@ -4,8 +4,11 @@ import { getSettings } from '@/common/funcs'; export default () => { const keyBindings = getSettings('keyBindings'); - const handler = async () => { + const handler = async ({ uuid }) => { const targetStore = useTargetStore(); + if (uuid) { + targetStore.setFallbackUUID(uuid); + } targetStore.open(); logseq.showMainUI({ autoFocus: true, diff --git a/src/stores/target.ts b/src/stores/target.ts index 472af77..e15f8f2 100644 --- a/src/stores/target.ts +++ b/src/stores/target.ts @@ -132,6 +132,7 @@ const processBlock = async (block: BlockEntity, destination: Destination) => { export const useTargetStore = defineStore('target', { state: () => ({ + fallbackUUID: '', visible: false, destination: { to: 'today', @@ -144,6 +145,12 @@ export const useTargetStore = defineStore('target', { pages: [], }), actions: { + setFallbackUUID(uuid: string) { + this.fallbackUUID = uuid; + }, + clearFallbackUUID(uuid: string) { + this.fallbackUUID = ''; + }, async loadPages() { const pages = await logseq.DB.datascriptQuery(` [:find ?page-name (pull ?page [*]) @@ -174,7 +181,10 @@ export const useTargetStore = defineStore('target', { } } } else { - const block = await logseq.Editor.getCurrentBlock(); + let block = await logseq.Editor.getCurrentBlock(); + if (!block) { + block = await logseq.Editor.getBlock(this.fallbackUUID); + } if (block) { processed = await processBlock(block, this.destination); if (!processed) { @@ -190,6 +200,7 @@ export const useTargetStore = defineStore('target', { } } + this.clearFallbackUUID(); logseq.hideMainUI({ restoreEditingCursor: true, });