Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
huyz opened this issue Aug 14, 2022 · 3 comments
Open

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

huyz opened this issue Aug 14, 2022 · 3 comments

Comments

@huyz
Copy link

huyz commented Aug 14, 2022

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

  • what if the internal page already exists? then there should be no need for an alias.
  • very often we want to highlight a word or phrase to add an internal link even if the internal page doesn't yet exist. In other words we purposefully create broken links so that one day we may create a note for it.

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
Copy link

ryadaj commented Aug 16, 2022

I second this motion

@tophee
Copy link

tophee commented Nov 29, 2022

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

Somehwere here, I guess:

editor.replaceSelection(`[[|${selected_word}]]`);
const current_line = editor.getCursor();
const wanted_position = current_line;
wanted_position.ch =
wanted_position.ch - (selected_word.length + 3);
editor.setCursor(wanted_position);
}
},
});
}
onunload() {}
}

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
Copy link

tophee commented Nov 29, 2022

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 ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants