salmund / obsidian-better-link-inserter

Use the selected word as an alias in link suggestion.
MIT License
48 stars 9 forks source link

How to make it better (not just different) #2

Open huyz opened 2 years ago

huyz commented 2 years ago

The default "Add internal link" actually has 2 use cases that are different from your plugin's:

Your plugin is useful for another use case: when we know we want to link to an existing note and set an alias.

So I actually need to set 2 hotkeys to handle all these cases.

But there is a way to actually make your plugin better than the default command. And that's if there's a way to fallback to the original behavior in real time. For example, after hitting your command, the cursor is positioned just before the | character and the autocompletion pop-up shows up; if I could then just hit Esc, then the pop-up would close and your plugin would remove the | character, then that would leave us with a more powerful combination.

ryadaj commented 2 years ago

I second this motion

tophee commented 1 year ago

This functionality should really be part of obsidian core... But until then, I guess some needs to make a PR...

Somehwere here, I guess:

https://github.com/salmund/obsidian-better-link-inserter/blob/8a7d2d0621267f26dc4db44941ae9b06d9ee1069/main.ts#L25-L38

I don't know js so I'm not sure where to start. One thing I don't understand is: once the autocompletion popup shows up (that should be after line 30, if I'm not mistaken), does the plugin unload (which would mean any code that removes the | would have to go into the onunload() {} section) or can we make it wait at line 30 to see if any file was selected in the autocomplete popup and if not, we delete the |and move to the end of the link?

tophee commented 1 year ago

what if the internal page already exists? then there should be no need for an alias.

Yet, maybe it is a good idea to always add an alias, even when it is identical with the actual file link, because if you do, the text wont change in case the file name is changed (see #5 ).