obsidian-api icon indicating copy to clipboard operation
obsidian-api copied to clipboard

De-couple `file-open` from `active-leaf-change`

Open tzhouhc opened this issue 3 years ago • 5 comments

Currently, the file-open event has a callback for the TFile opened. However, it provides no information as to the containing leaf of said TFile. I tried iterating through all open leaves, but found out that apparently they all contain the same TFile by reference, so... Is there not an actual way to find out the leaf for a file-open event?

tzhouhc avatar Jan 02 '22 11:01 tzhouhc

The file-open is always triggered for the Workspace.activeLeaf. Just to be certain, however, I still suggest running a null check and comparing the TFile, but it should only fire for the active leaf.

lishid avatar Jan 03 '22 13:01 lishid

Ah, thank you for the pointer!

tzhouhc avatar Jan 04 '22 00:01 tzhouhc

I discovered that file-open events fire for active-leaf-change as well, which is not quite the expected behavior with two events named as such. I was more hoping that file-open would only fire for either a new leaf or a leaf getting a new file opened in it.

So maybe I can retitle the request to be "de-couple file-open from active-leaf-change"?

tzhouhc avatar Jan 04 '22 01:01 tzhouhc

I would say that I don't want to change its behavior for backwards compatibility reasons, but we could look into adding a proper event for "file was just opened". Let's leave this issue open until that's available.

lishid avatar Jan 04 '22 02:01 lishid

Sounds good! Yeah I agree, the breakages would be very unfunny.

tzhouhc avatar Jan 04 '22 02:01 tzhouhc