Skip to content

Commit

Permalink
fix: support goto collapsed blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
sethyuan committed Dec 13, 2023
1 parent 1a620b5 commit 52c38bf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logseq-plugin-tocgen",
"version": "2.12.3",
"version": "2.12.4",
"main": "dist/index.html",
"logseq": {
"id": "_sethyuan-logseq-tocgen",
Expand Down
1 change: 1 addition & 0 deletions src/comps/Block.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function Block({
block.name != null && block.children[0]
? block.children[0].uuid
: block.uuid,
block.name != null && block.children[0] ? block.id : block.parentID,
)
}
},
Expand Down
1 change: 1 addition & 0 deletions src/comps/TocGen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default function TocGen({
name: src.name,
content,
collapsed: collapsings[src.id] ?? level >= expansionLevel,
parentID: src.parent?.id,
children,
}
},
Expand Down
16 changes: 15 additions & 1 deletion src/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ export function waitForEl(selector, timeout) {
return new Promise(tryFindEl)
}

export async function gotoBlock(pageName, blockUUID, count = 0) {
export async function gotoBlock(pageName, blockUUID, parentID, count = 0) {
await expandAncestors(parentID)

logseq.Editor.scrollToBlockInPage(pageName, blockUUID)

// Avoid infinite loop
Expand Down Expand Up @@ -158,3 +160,15 @@ export async function gotoOffset(container, scrollTop) {
await waitMs(300)
}
}

async function expandAncestors(id) {
let parent = await logseq.Editor.getBlock(id)
while (parent) {
if (parent["collapsed?"]) {
await logseq.Editor.setBlockCollapsed(parent.uuid, false)
}
parent = parent.parent
? await logseq.Editor.getBlock(parent.parent.id)
: null
}
}

0 comments on commit 52c38bf

Please sign in to comment.