Steps to reproduce
- Add a PDF to the vault. For example, you can use this sample PDF.
- Open a markdown view on the left and a PDF view on the right.
- Click the markdown view.
- Then, click the PDF view. Now, the PDF view is the active view.
- Open the command palette and close it.
Did you follow the troubleshooting guide? [Y/N]
Y
Expected result
Because the PDF view was active before opening the command palette, it should be kept active after closing the command palette.
Actual result
The focus is moved to the markdown view on the left. This makes it impossible for some plugin commands to work properly (the affected plugins include PDF++). See “Additional Information” section for the details.
Environment
SYSTEM INFO:
Obsidian version: v1.8.9
Installer version: v1.8.9
Operating system: Darwin Kernel Version 22.6.0: Mon Feb 19 19:43:41 PST 2024; root:xnu-8796.141.3.704.6~1/RELEASE_ARM64_T8103 22.6.0
Login status: logged in
Language: en
Catalyst license: insider
Insider build toggle: on
Live preview: on
Base theme: adapt to system
Community theme: none
Snippets enabled: 0
Restricted mode: off
Plugins installed: 0
Plugins enabled: 0
RECOMMENDATIONS:
none
Additional information
- The third step seems redundant, however if you skip it, the bug cannot be reproduced.
- If I click in the page number box in step 4, the bug does not happen and the PDF view is kept active.
- Update: it turned out that it’s not command-palette-specific. It also happens with other types of modals (maybe modals with
shouldRestoreSelection
set totrue
?). For example, try quick switcher and commands like “Show debug info” and “Open settings”. - I guess the bug happens because clicking on the PDF view does change the active leaf but does not change the DOM focus (for example,
getSelection().anchorNode
anddocument.activeElement
remains in the markdown view). In other words, the Obsidian workspace focus and the DOM focus are not synchronized properly. - To make it easier to see the effect of this bug, I made an example plugin with a simple command that uses the active PDF view. You can see this bug makes it impossible for this command to run successfully even when the command shows up in the command palette. I have described the detailed steps to reproduce the issue in README of the plugin.
- I think this bug might be related to the recent updates around the PDF view focus issue. There is another bug report that seems to be related to the same issue.