From 911b77764c74759cd12b4a57a8a9105ed32aa7de Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Thu, 23 Nov 2023 15:21:14 +0100 Subject: [PATCH] fix: Prevent default click behavior when jumping to a task (#2446) * Prevent default click behavior on a task jump * Improve comment and remove outdated comment --- src/QueryRenderer.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/QueryRenderer.ts b/src/QueryRenderer.ts index f8023a6b9d..ed2bec8dcf 100644 --- a/src/QueryRenderer.ts +++ b/src/QueryRenderer.ts @@ -352,12 +352,11 @@ class QueryRenderChild extends MarkdownRenderChild { if (result) { const [line, file] = result; const leaf = this.app.workspace.getLeaf(Keymap.isModEvent(ev)); - // This opens the file with the required line highlighted. - // It works for Edit and Reading mode, however, for some reason (maybe an Obsidian bug), - // when used in Reading mode, switching the result to Edit does not sync the scroll. - // A patch suggested over Discord to use leaf.setEphemeralState({scroll: line}) does not seem - // to make a difference. - // The issue is tracked here: https://github.com/obsidian-tasks-group/obsidian-tasks/issues/1879 + // When the corresponding task has been found, + // suppress the default behavior of the mouse click event + // (which would interfere e.g. if the query is rendered inside a callout). + ev.preventDefault(); + // Instead of the default behavior, open the file with the required line highlighted. await leaf.openFile(file, { eState: { line: line } }); } }); @@ -373,6 +372,7 @@ class QueryRenderChild extends MarkdownRenderChild { if (result) { const [line, file] = result; const leaf = this.app.workspace.getLeaf('tab'); + ev.preventDefault(); await leaf.openFile(file, { eState: { line: line } }); } }