shichongrui / obsidian-reveal-active-file

Obsidian plugin to reveal the active file automatically when you open a file
86 stars 10 forks source link

Active pane loses focus when opening a file in Obsidian 0.15.3 #11

Open Randy-Astle opened 2 years ago

Randy-Astle commented 2 years ago

Obsidian version: 0.15.3 Pane Relief version: 0.1.8 Automatically Reveal Active File version: 1.0.2

When both Pane Relief and Automatically Reveal Active File are installed, the Pane Relief commands to move between editor panes doesn't work correctly. If I have 3+ editor panes, end up toggling between just two panes - and it looks like the left toolbar (specifically file explorer) gets the focus in the process.

As I understand it, there have been some significant changes in Obsidian 0.15.x with how panes are handled. Perhaps your extension needs to be updated.

pjeby commented 2 years ago

The issue is that in 0.15 the "reveal active file" command puts focus on the explorer pane. In order to not do that, the plugin would need to save the active leaf and restore it afterwards, or else trigger the reveal using another method that does not specifically open and activate the file explorer pane.

This problem doesn't actually have anything to do with Pane Relief: you can reproduce it in the sandbox vault on 0.15.3 with this installed as the only plugin. (@Randy-Astle, you might want to edit the title to reflect this, perhaps something like "active pane loses focus when opening a file in Obsidian 0.15.3", as that is what is causing your problem, and is also a problem for the plugin in general, as it requires people hit Escape after opening every file in order to work with it).

anselmwang commented 2 years ago

Fix this issue with #13. I have attached the compiled plugin. Would you mind to test whether this meet your requirements? obsidian-reveal-active-file.zip

JimKnecht commented 2 years ago

I have the same focus issue with this plug that manifests in 2 ways:

1) when I create a new file in a folder by right click, new file I have to click in the name field to name the file, without this plugin installed I don't have to do that.

2) plugin still highlights the file but it doesn't scroll it into view if the tree is long enough to be off screen.

Here's hoping it can be fixed as this is one of the plugin I really love since I usually have several files open at once with a big tree.

pjeby commented 2 years ago

For anyone who needs an immediate solution for this, the Pane Relief plugin now includes a "Focus Lock" feature that prevents sidebar panes from stealing focus from the main panes. Basically, it makes Obsidian act like it used to for this plugin and many others, but the feature can be turned on and off with the mouse (click the lock in the status bar) or keyboard if you need to temporarily make the sidebar focusable, e.g. to edit a note in the sidebar. The toggle remembers its state across restarts, so you don't have to remember to switch it on each time.

Edit: Whoops, I spoke too soon. Pane Relief's focus lock prevents the file explorer pane from becoming active, but it doesn't stop it from stealing focus, which remains a problem. Sorry for getting anyone's hopes up!

pjeby commented 2 years ago

Update: Pane Relief 0.2.5 now prevents the file explorer pane from stealing focus when triggered by the Reveal Active File plugin or by the keyboard command, when focus lock is on. So you can use it as a fix for this issue now.

pjeby commented 2 years ago

Yet another update: Pane Relief 0.2.7's focus lock now keeps the file explorer from stealing focus when you're in a secondary/popout window as well, so you don't have to choose between using the reveal-active-file plugin, and being able to use secondary windows.

c33s commented 11 months ago

with obsidian 1.1.16 and automatically reveal active file 1.0.2 i have the problem of losing focus to the side pane (directory tree) if i work with multiple windows or split panes. is this the same issue as described in this issue or should i open a new issue? i will give pane relief a try, hopefully the lock focus setting help

edit: just tried pane relief, still the same problem: if i open a 2nd window and try to focus it, the focus jumps back to the first window. i have to click fast and multiple times on the 2nd window to get the focus there

hsandt commented 7 months ago

The issue was very visible when navigating through tabs with Ctrl+PageUp/PageDown repeatedly, as it would suddenly focus the Files hierarchy and start navigating across the left side panel: Files > Search > Bookmarks instead.

I confirm that installing plugin Pane Relief and using command "Pane Relief: Cycle to previous/next tab in this window" will work by ignoring side bar focus (Obsidian 1.5.3). Make sure to remove binding Ctrl+PageUp/PageDown to native commands "Go to previous/next tab" to avoid conflicts.

EDIT: I still found a limitation for general use: despite focus being kept on active file content in appearance, Obsidian will still think that we are not in file edit mode and as a result, will not display commands for that scope when using Ctrl+P to open the command palette.

Repro:

This becomes an issue when chaining other navigation commands such as plugin Navigate Cursor History's own commands: Navigate Cursor History: Go back/forward, as they will stop working after the file was highlighted.

So while installing Pane Relief fixes tab navigation, other forms of navigation won't be fixed as each plugin would require that "ignore sidebar focus" feature which demands more work from every other plugin developer. So maybe the PR in work https://github.com/shichongrui/obsidian-reveal-active-file/pull/13 is our best bet at the moment.

It may also be fixed on Obsidian API side by providing us a variant of file-explorer:reveal-active-file which would not lose editor focus, name could be file-explorer:reveal-active-file-keep-focus or so.

pjeby commented 7 months ago

For the people who are using Pane Relief, please note that in order to prevent the navigation issue, you have to turn on Focus Lock. That's the little padlock icon in the status bar: if it shows unlocked, click it to lock it. Once locked, you'll be able to navigate just fine without any of the problem you're reporting.