Improved #51 and fixed #80

This commit is contained in:
Simon Cambier
2022-07-14 08:24:31 +02:00
parent cdce2b5f0e
commit 6b64cd80b4
4 changed files with 14 additions and 18 deletions

View File

@@ -62,23 +62,20 @@ export async function openNote(
reg.exec(item.content)
const offset = reg.lastIndex
// Check if the note is already open
// const pane = MarkdownView.getPane(item.path)
// Check if the note is already open,
// to avoid opening it twice if the first one is pinned
let existing = false
let alreadyOpenAndPinned = false
app.workspace.iterateAllLeaves(leaf => {
if (leaf.view instanceof MarkdownView) {
if (leaf.getViewState().state?.file === item.path) {
if (!newPane && leaf.getViewState().state?.file === item.path && leaf.getViewState()?.pinned) {
app.workspace.setActiveLeaf(leaf, false, true)
existing = true
alreadyOpenAndPinned = true
}
}
})
if (!existing) {
// Open a new note
if (!alreadyOpenAndPinned) {
// Open the note normally
await app.workspace.openLinkText(item.path, '', newPane)
}