From acd3b700a1c58c76a3e10797607f8aa2dd743dd0 Mon Sep 17 00:00:00 2001 From: Frederic Brodbeck Date: Fri, 24 Mar 2023 17:30:50 +0100 Subject: [PATCH 1/3] clean up --- src/components/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index ffd71f8..7fc4949 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -31,7 +31,7 @@ const selectionHandler = async ( expand: boolean, ) => { if (!item) { - return console.info('nothing selected'); + return; } if (expand) { await Promise.all( From 68204d0a2492fdfe0121f87314e43475b86ac6b6 Mon Sep 17 00:00:00 2001 From: Frederic Brodbeck Date: Fri, 24 Mar 2023 17:31:57 +0100 Subject: [PATCH 2/3] made it semi-work for sub-trees --- src/components/App.tsx | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 7fc4949..4208d97 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -18,10 +18,19 @@ type PathItem = { const scrollTo = async (blockUuid: string) => { - const page = await logseq.Editor.getCurrentPage(); + const pageOrBlock = (await logseq.Editor.getCurrentPage()); + const isBlock = ('content' in (pageOrBlock || {})); + if (!pageOrBlock) { + return console.error('failed to get page or block'); + } + const page = isBlock + ? await logseq.Editor.getPage(pageOrBlock.page.id) + : pageOrBlock; if (!page) { - return console.error('failed to get current page'); + return console.error('failed to get page'); } + // TODO: how to scroll to block in sub-tree without leaving the sub-tree? + // `scrollToBlockInPage()` will open the entire page logseq.Editor.scrollToBlockInPage(page.name, blockUuid); }; @@ -114,10 +123,29 @@ function App() { () => { const visibilityHandler = async ({ visible }: { visible: boolean }) => { if (visible) { - const blocks = await logseq.Editor.getCurrentPageBlocksTree(); + const pageOrBlock = await logseq.Editor.getCurrentPage(); + if (!pageOrBlock) { + return closeHandler(); + } + + // NOTE: `logseq.Editor.getCurrentPageBlocksTree()` won't return anything if + // we're in a sub-tree rather than a full page. + let blocks: BlockEntity[] = []; + if ('content' in pageOrBlock) { + const block = await logseq.Editor.getBlock( + (pageOrBlock as BlockEntity).uuid, + { includeChildren: true } + ); + if (block) { + blocks = [block]; + } + } else { + blocks = await logseq.Editor.getCurrentPageBlocksTree(); + } if ((blocks || []).length === 0) { return closeHandler(); } + const maxDepth = 3; // TODO: make this configurable const items = makeCommands(blocks, maxDepth); setItems(items); From e845971531698b848763f82d3426d625b9ac37e5 Mon Sep 17 00:00:00 2001 From: Frederic Brodbeck Date: Fri, 24 Mar 2023 17:34:40 +0100 Subject: [PATCH 3/3] version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index da5a1c2..73a4f26 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "logseq-plugin-jump-to-block", - "version": "1.1.1", + "version": "1.1.2", "main": "dist/index.html", "logseq": { "id": "logseq-plugin-jump-to-block"