czottmann / obsidian-mononote

An Obsidian plugin that ensures each note occupies only one tab. If a note is already open, its existing tab will be focussed instead of opening the same file in the current tab.
https://obsidian.md/plugins?id=zottmann
MIT License
89 stars 2 forks source link

Bug: Mononote breaks some "Advanced URI" links #17

Closed kankaristo closed 7 months ago

kankaristo commented 7 months ago

I have the Advanced URI extension installed, and Mononote seems to break some of those links.

A have a link like this in tab 1 in pane 1: [link text](obsidian://advanced-uri?vault=vaultname&filepath=filename&line=10)

And that file is already open in pane 2, along with some other files in the same pane.


With Mononote disabled, the link works as intended, and it actually focuses the existing tab with that file, and doesn't open a new tab.

But with Mononote enabled, the link opens a new tab (in the same pane with the existing tab), Mononote immediately closes the new tab, and focus is left in the last tab in that pane. So with Mononote, the wrong tab is focused.

I think this could be solved just by Mononote ignoring all Advanced URI links, since they already focus on an open tab, if there is one.

czottmann commented 7 months ago

Thanks for the report, @kankaristo! Two things:

  1. Does this happen w/ Mononote 1.1.1, i.e. are you're using the current version?
  2. Mononote does not interfere with links – it works by hooking into an Obsidian event that is fired when the active tab is changed. Obsidian doesn't convey the origin of the action, i.e. which link was clicked in what tab, or even if the link came from outside the app etc., so there's nothing for Mononote to filter, I'm afraid.
kankaristo commented 7 months ago

Yes, I'm using Mononote 1.1.1.

I did a bit more testing, and it's starting to look like this is more of a bug in Advanced URI, and it's a way more obscure scenario than I thought, since it also requires pinning tabs. Mononote kind of makes the bug worse, but it's still more of a bug in Advanced URI.

The smallest reproducible case is basically:

| Pane 1    | Pane 2        |
|-----------|---------------|
| fileA     | fileB | fileC |

fileA has an Advanced URI link like this (the vault and line number from my original report aren't necessary):

[test](obsidian://advanced-uri?filepath=fileB.md)

The tabs for fileA and fileB are both pinned (it's enough for fileB to be pinned, but the bug changes a bit, and what I've described below is with both tabs pinned).

Then, when you click the link (in fileA), the tab with fileB is momentarily focused, then a new tab for fileB is opened and focused (in pane 2). All of this behavior comes from Advanced URI, and it shouldn't be opening a new tab in this case, but it somehow gets confused by the pinned tabs...

Then, if Mononote is enabled, it closes the new tab with fileB, and focus goes to the tab with fileC (which is the last/rightmost tab in the pane). So the bug becomes a bit worse, since a completely unrelated tab gets focus, but the main bug seems to be in Advanced URI (which shouldn't be opening a new tab), and not in Mononote.

So, feel free to close this, if the scenario is a bit too obscure (requires 2 plugins, and specifically pinned tabs). I think I can avoid the bug by not using pinned tabs, let's see if I can live with that workflow (maybe I can thanks to Mononote :smile:).