From e5abaa641d828f36a9d3d703e4abb7de45719666 Mon Sep 17 00:00:00 2001 From: Adit Sharda Date: Mon, 20 May 2024 20:47:43 -0400 Subject: [PATCH] fix: Always get current block content Use getEditingBlockContent instead of getCurrentBlock to always get the latest value. Get's rid of an issue where sometimes Jira issue key existed but wasn't detected. --- src/main.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index 6f77c06..339125d 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -100,20 +100,19 @@ async function main() { async function updateJiraIssue(useSecondOrg: boolean = false): Promise { try { const currentBlock = await logseq.Editor.getCurrentBlock(); + const value = await logseq.Editor.getEditingBlockContent(); // This has more current content (whereas currentBlock.content is stale) - if (!currentBlock?.content) { - logseq.UI.showMsg("Couldn't find a valid Jira issue key.", 'error'); - throw new Error("Couldn't find a valid Jira issue key."); + if ( currentBlock === null) { + throw new Error('Select a block before running this command'); } - - const value = currentBlock.content; - const uuid = currentBlock.uuid; + + const uuid = currentBlock?.uuid; const issuesList = extractIssues(value); if (!issuesList || issuesList.length < 1) { - logseq.UI.showMsg("Couldn't find any Jira issues in this block.", 'error'); - return; + logseq.UI.showMsg("Couldn't find any Jira issues.", 'error'); + throw new Error("Couldn't find a valid Jira issue key."); } const issues = await getIssues(issuesList, useSecondOrg);