scambier / obsidian-no-dupe-leaves

Automatically switch the focus to open notes instead of reopening them
GNU Affero General Public License v3.0
60 stars 6 forks source link

Does plugin still work? #1

Closed pm64 closed 2 years ago

pm64 commented 2 years ago

Is this plugin expected to work with Obsidian 0.15.9? I am observing that Obsidian continues to open duplicate leaves, even though the plugin is enabled.

scambier commented 2 years ago

I'm on 0.15.9 (no-dupe-leaves 0.0.4) and it works 🤷‍♂️

Could you try while disabling the other plugins? Also, disable and re-enable no-dupe-leaves (after disabling other plugins) to make sure that the patch is correctly applied.

pm64 commented 2 years ago

I disabled all core and community plug-ins except for File Explorer, obsidian-no-dupe-leaves, and Sync, and also reverted to the stock theme. I then disabled and re-enabled obsidian-no-dupe-leaves. Unfortunately this had no effect on the behavior I'm seeing:

  1. In empty workspace, open document no. 1. It opens in pane A.
  2. Ctrl+click a 2nd document to open it in a new pane B.
  3. With pane B active, click document no. 1 again
  4. 2nd instance of document no. 1 opens in pane B.
  5. Document no. 1 is now opened in both panes A and B.
scambier commented 2 years ago

It's indeed buggy when you open from the file explorer... Which is something I absolutely never do 😅 I'll fix this asap, thanks for reporting.

pm64 commented 2 years ago

Thanks @scambier. On a related note, while I have your ear, may I ask if there are any plug-ins that obsidian-no-dupe-leaves is known to interfere with?

scambier commented 2 years ago

None to my knowledge - it's a very small plugin with few downloads, so I don't have a lot of feedback. But technically, it may interfere with any plugin that also rewrites the "open file" functions; I did my best to follow the best practices, but bugs happen :)

pm64 commented 2 years ago

I'm surprised by the low adoption. The default behavior of opening multiple file instances seems like it would be contrary to the expected behavior for the majority of users. Perhaps this behavior made more sense before the live preview editor was added? In any case, thanks for all you do.

DutchPete commented 2 years ago

It does not work with 0.16, unfortunately!!

pm64 commented 2 years ago

@DutchPete, see above. Are you loading files using the file explorer? If so, this isn't currently expected to work, but @scambier is fixing it.

DutchPete commented 2 years ago

@pm64 I usually files by opening a list with ⌘ + O, selecting the file I want and opening it with ⌘ + click. I just rechecked this and indeed a 2nd instance of a file already open is opened.

scambier commented 2 years ago

What is your ⌘ + O bound to? Also, ⌘ + click will force open a new tab in most (all?) plugins.

At this moment, no-dupe-leaves only wraps the openLinkText() function, which is called when clicking on a link in a note. It's also used by some plugins, like Omnisearch.

scambier commented 2 years ago

Current status: intercepting openLinkText() is easy because a) it's an exposed function and b) it's at the "top" of the calling chain. Opening a note through the file explorer uses lower, non-public functions, that are triggered by a chain of events. While I was able to capture the "open file from explorer" event, I can't do it early enough in the app lifetime to overwrite the default behavior.

And even if I did, it's a brittle solution which might end up having unintended consequences. So, sorry, but I won't fix this 😔

pm64 commented 2 years ago

@scambier, would you consider a solution that worked by immediately "closing" the duplicate (perhaps by popping it off of the pane history), then focusing the already-open instance of the document?

DutchPete commented 2 years ago

What is your ⌘ + O bound to? Also, ⌘ + click will force open a new tab in most (all?) plugins.

At this moment, no-dupe-leaves only wraps the openLinkText() function, which is called when clicking on a link in a note. It's also used by some plugins, like Omnisearch.

Since you have closed this issue, I suppose I should not answer, but I will, just for the record.

It is not my ⌘ + O, it is the standard shortcut for Quick Switcher. I thought ⌘ + click prevents opening a 2nd instance of an already open note. If that is not the case, then what is the plug-in for?

scambier commented 2 years ago

@pm64 I won't promise anything but I can take a look. Again, I don't want to break anything by toying with Obsidian's internals - you wouldn't like it if the contents of a note were replaced with another's.

@DutchPete Obsidian's default behavior is the following: image

The issue I'm trying to solve with this plugin is having the same note open twice with the normal click: image

The ctrl/cmd/middle+click is standardized in all plugins as "open in a new tab", and I don't wish to overwrite this behavior. I just want to fix the fact that I end up with 2 identical notes when that's not what I explicitely asked.

DutchPete commented 2 years ago

I just want to fix the fact that I end up with 2 identical notes when that's not what I explicitely asked.

Right, that is what I thought the plug-in was about. So, in practical terms, how can I, as a user of the plug-in, avoid opening a 2nd instance of a note?

For example, if I open Quick Switcher to find a note, and let's say I am not aware the note I want is already open. So, in the list I am presented with by QS I click on the title of the note that is already open, will that open a 2nd instance or not?

If it will open a 2nd instance, then how am I supposed to use the plug-in to avoid that?

pm64 commented 2 years ago

@scambier thanks for your continued research on this issue. I believe the solution I propose is unlikely to cause unexpected behavior, since it only automates a sequence of operations the user can perform manually by interacting with the UI.

scambier commented 2 years ago

@DutchPete at this moment, the plugin patches the openLinkText() function - it literally takes the function from Obsidian API and rewrites it. So it works when clicking on a link within a note, or through plugins that also use this function, like Omnisearch. Conveniently for me, that's how I navigate in Obsidian so it fixes my workflow. I made this plugin public hoping that it would help other users too.

Since the File Explorer and Quick Switcher plugins use different functions (and are way harder to patch safely), they still have the default behavior.

DutchPete commented 2 years ago

OK, that makes it clear now! So, I will keep the plug-in because I also open links from within a note.

Many thanks for your patience with my badgering.

scambier commented 2 years ago

No problem :) Like I said it worked for me so I thought "good enough I guess", and did not even try those core plugins. I updated the README to make that clearer 👍

trainbuffer commented 2 years ago

Ahh, this is good to know. I'm playing with .16.x and clicking in the File Explorer more than I have in the past messing around. No-dupe-leaves seemed to work sometimes but not others and I was scratching my head.

For me, in 0.16.5, clicking an internal link focuses a tab (if already open), but clicking FileExplorer or using ⌘ + O show the default behavior. Bummer. But, as @DutchPete said, keeping this plugin for sure!!

nmay231 commented 6 months ago

There's an alternative plugin that seems to work in many use cases, including the sidebar, because it's implemented fundamentally differently: https://github.com/czottmann/obsidian-mononote

That plugin supports more of my workflow so I will be using it, but I do want to thank you so much for putting this plugin out there so it can be useful to others :)

scambier commented 6 months ago

Thank you :)