Skip to content

Commit

Permalink
fix: Prevent default click behavior when jumping to a task (#2446)
Browse files Browse the repository at this point in the history
* Prevent default click behavior on a task jump

* Improve comment and remove outdated comment
  • Loading branch information
Cito authored Nov 23, 2023
1 parent 68144dd commit 911b777
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/QueryRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } });
}
});
Expand All @@ -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 } });
}
}
Expand Down

0 comments on commit 911b777

Please sign in to comment.