One scenario to examplify what I’m looking for:
Let’s say we’ve got two notes, NoteA with a link [[EndNote#first]], and NoteB with a link [[EndNote#second]]. I’m currently in NoteA, and I hit the link
Primary goal: That this time I came from NoteA,
Secondary goal: or that the link which opened EndNote this time was in fact the [[EndNote#first]] link?
Is either of these goals achievable somehow? Is there something hidden in the app or dv (or some other variables), which reveals which link triggered the opening of the current note?
( Tertiary(?) goal: Is there some event I could hook on to, before/when the open occurs, where some of this information could be available? )
The use case this could solve for me
If something like this is possible, I’m contemplating on removing loads of my non-existent notes to people, with a common page, and then create aliases all over the places to “headings” within my common page, and then detect where these came from.
Say this page was called “Unknowns”, I could have a link to [[Unknowns#ElonMusk]] or [[Unknowns|Elon Musk]], and hopefully I could know which variant triggered the Unknowns page the last time, and focus on that.
Hmm… Would it be sufficient to actually just use the [[Unknowns#Elon Musk]] link? Maybe, but I would really like to know if this possible using a query, somehow.
If your goal is just to link to a particular heading, then yeah, the heading link is all you need. I’m not sure if the link-origin stuff you’re asking about is meant to help reach the right destination or if that’s something you want in addition to that.
I’m asking for detection on what triggered the opening of the note programmatically.
I know. I wasn’t sure why after reading your use case section. I don’t see any explicit mention of what you want to use that info for. It sounded like you might want it to determine where in the linked-to page to focus, and in the last paragraph it sounds like you might be thinking you don’t actually need it because heading links do that (but you’re still curious now that the question has come up). Alternately, it seemed possible to me that what you meant was that you wanted to display that info at the destination — but that seemed less supported by the use-case description.
I moved the post because it sounded like you were trying to accomplish something in your vault, not developing a plugin or interacting with the API. Sorry for misunderstanding.
There might be an even better way, but this works for me. It’s just getting the path of the previously opened file, which would presumably be the one that you were on before clicking into the current note.
Interesting fubction, but I do explicitly want to know the link triggering the open to current file.
Sorry, if I was unclear, but I do want to use out to focus in the current page. Potentially I’m thinking about auto folding other parts, or similar ways to narrow down the focus in the current note.
Seen from my (poorly described) use case I’d want to “hide” the other unknowns. This way I don’t have to have a bunch of non vital person notes in my vault, but can limit that to a catch-all for those that I don’t know that much about.
FYI following a link to a folded section unfolds it, so you could get a more laborious version of what you want by using the “Fold all” command when you’re done with the Unknowns page. Obviously that’s not ideal but it might be useful for testing the experience, or as a stopgap (or not).
@holroy I came across this repo while looking for something else, and it looks perfect for you to get the needed code from:
This plugin for Obsidian remembers the cursor position and scroll for each note. This is very convenient when you switch between notes, go from link to link, go back, you do not need to scroll to the place where you were the last time.