Vinzent03 / obsidian-advanced-uri

Advanced modes for Obsidian URI
MIT License
765 stars 44 forks source link

Allow `openmode` on `commandname` or `commandid` URIs #163

Closed cromo closed 3 months ago

cromo commented 8 months ago

I would like to be able to specify an openmode and run a command afterward. My use case is to create a new window and then run the create unique note command so that I get a floating window that I can move over/around the thing I'm taking notes on without affecting my main Obsidian layout.

I have a workaround for this right now because command URIs can specify filepaths. I had to look into the code to see what exactly had to be done to pass the openmode parameter to the open call -

  1. Create a dummy file that will always be empty
  2. Create a command URI
  3. Add a filepath parameter pointing at the dummy file, and a mode=overwrite parameter (since we need to have a mode specified in order to reach the code path that calls this.plugin.open, also, this is why I kept the dummy file empty - it's just going to get emptied anyway)
  4. Now add an openmode parameter

My final workaround looks something like this:

obsidian://advanced-uri/?vault=notes&commandid=zk-prefixer&filepath=dummy-file&mode=overwrite&openmode=window

Or spread out for readability:

obsidian://advanced-uri/
  ? vault=notes
  & commandid=zk-prefixer
  & filepath=dummy-file
  & mode=overwrite
  & openmode=window

Not having to have a dummy file to open a new window would be strongly preferred, but this workaround does roughly what I need it to do.

Vinzent03 commented 7 months ago

Shouldn't this else case be sufficient, so you don't need to pass a mode? So you can just any filepath. I don't think, adding an open call if you pass no filepath to be opened, is a good idea.

cromo commented 6 months ago

I finally got around to testing it, and yes, I can omit the mode and it still do what I want. However, I still need to pass a filepath to get to that branch in the code.

I don't really know how the code is structured underneath, but the reason I want to be able to open a new window without specifying a file is because the command I'm running creates a new file - and thus I don't need to open a file to run the command but I do want a new window to run the command in. It would be a little nicer in this case to not have to open an intermediate file. What about allowing creating a new window with the default Obsidian "New tab" instead? That would make use cases like this cleaner.

For completeness, my current URL is:

obsidian://advanced-uri/?vault=notes&commandid=zk-prefixer&filepath=dummy-file&openmode=window
Vinzent03 commented 3 months ago

Is now available in v1.43.0 :tada:

cromo commented 2 months ago

Thank you for taking the time to understand my use case and help me work through this until the feature landed! I just checked and it works exactly as I hoped. Now my URL is:

obsidian://advanced-uri/?vault=notes&commandid=zk-prefixer&openmode=window

Much simpler!