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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

For completion, default to links/aliases, make leading #/^ complete for anchors/blocks #589

Closed
linduxed opened this issue May 17, 2024 · 7 comments 路 Fixed by #590
Closed

Comments

@linduxed
Copy link

馃殌 The feature, motivation and pitch

Since v3.7.0, the addition of support for anchor and block search has resulted in the default behavior of the completion to change.

Previously typing [[ would (after a configurable amount of characters) initiate search among the note names and their aliases, much like how Obsidian works. The recent addition of the support for anchors and blocks changes two things:

  1. The completions no longer resemble the default behavior of Obsidian, due to Obsidian requiring a prefix after [[ for initiating a completion different than note names and aliases ([[# for headings in the current note, [[## in all notes; [[^ for blocks in this note, and [[^^ in all notes).
  2. The amount of completions to process in the vault increases, meaning that the time before the completion menu pops up has increased notably.

While having the ability to get completion for anchors and blocks is useful, to both be more in line with the working of Obsidian, and to avoid the performance penalty of always completing for everything (notes, aliases, anchors, and blocks), would it be a good idea to introduce a similar kind of prefix detection (i.e. looking for something like [[#) to the completion triggering?

Alternatives

An alternative would be making it possible to disable the anchor and block completion, to go back to the previous way things worked. The README made me think that this should be possible by changing the wiki_link_func config opt, but (unless I've missed something) this does not seem to do the trick.

Additional context

No response

@epwalsh
Copy link
Owner

epwalsh commented May 17, 2024

Hey @linduxed, I like the idea of only giving header/anchor link completion when the current prompt ends with # or ^. That seems perfectly reasonable to me and I think would regain the previous performance. I didn't know about Obsidian's [[## / [[^^ global search prompt, but that seems like a good feature to add here as well.

@epwalsh
Copy link
Owner

epwalsh commented May 17, 2024

I like the idea of only giving header/anchor link completion when the current prompt ends with # or ^.

@linduxed I just opened a PR for this. Can you test this out?

@linduxed
Copy link
Author

Hello @epwalsh! Thank you for the very quick response and code!

I checked out the PR locally and tested. Observations:

  1. The PR does indeed make it so that [[ only searches for note names.
  2. [[ does not show aliases in the completion. Not sure if this is expected or not.
  3. The searching for headers/anchors is either confusing to me as to how it should be used, or something is not working:
    a. Writing [[# does not seem to give any results.
    b. Writing [[## seems to give a short list of inaccurate results: I have a Purchases.md note with a ## Books heading, and this heading does not get found, while 3 other results that are totally unrelated get returned. The same 3 results seem to be returned for some other queries, so the text after [[## does not seem to matter. For a brief moment, however, there seems to be a flash of a long list of completion results that cover the screen, and maybe those results are good, but the flash is too quickly gone to tell.

@linduxed
Copy link
Author

Oh, wait, my bad:

when the current prompt ends with # or ^.

I misunderstood. That seems to work. In that case, I guess my only relevant observation is the part about aliases not being shown.

@linduxed
Copy link
Author

Further observations upon closer inspection:

  1. Now that I understand how to invoke the header functionality, the completions seem to contain false positives. Example: I have a note that's called Purchases.md with a header called ## Books, and a note called Purchase of apartment.md that does not have a header containing the word "books". Nonetheless, Purchase of apartment#books is one of the completions for [[purchase#books.
  2. Aliases are indeed there in the completion for [[, but they get listed in the completion as actual notes, and get inserted as actual note titles. Example: let's presume I have a note called Books.md with the alias To read. To read will be listed as a completion, and if one selects that, at least what one would expect that what would be inserted as text in the document would be [[Books|To read]], but instead [[To read]] is inserted.

@linduxed
Copy link
Author

Question: how is one to reference headers in the same document with this PR, excluding writing out the name of the current note and then the header (i.e. in a note called Foo.md, writing [[Foo#?

@linduxed
Copy link
Author

Would you want me to move some of the content in my previous messages to the PR thread, to have it all in context there?

linduxed added a commit to linduxed/dotfiles that referenced this issue May 19, 2024
This patch includes a revert of the changes in commit
60dde3d.

The changes introduced in `v3.7.0` pertaining to searching/completion
for anchors/headers/blocks were introduced in such a way that it breaks
the workflow that resembled the one found in Obsidian, i.e. completing
with either note names or aliases for them. Now, aliases are somewhat
broken (they're there, but they're not inserted as link text properly)
and the anchor data slows completion down and makes the results more
messy.

Discussion with the plugin author is currently ongoing in a GitHub
[issue][1] and its related PRs:

  1: epwalsh/obsidian.nvim#589

In 60dde3d, the configuration for `obsidian.nvim` was updated to comply
with the format that can be seen in `v3.7.x`, where it was previously
written for `v3.6.x`.

This commit should be reverted once the issues with the latest plugin
versions have been addressed.
linduxed added a commit to linduxed/dotfiles that referenced this issue May 19, 2024
This patch includes a revert of the changes in commit
60dde3d.

The changes introduced in `v3.7.0` pertaining to searching/completion
for anchors/headers/blocks were introduced in such a way that it breaks
the workflow that resembled the one found in Obsidian, i.e. completing
with either note names or aliases for them. Now, aliases are somewhat
broken (they're there, but they're not inserted as link text properly)
and the anchor data slows completion down and makes the results more
messy.

Discussion with the plugin author is currently ongoing in a GitHub
[issue][1] and its related PRs:

  1: epwalsh/obsidian.nvim#589

In 60dde3d, the configuration for `obsidian.nvim` was updated to comply
with the format that can be seen in `v3.7.x`, where it was previously
written for `v3.6.x`.

This commit should be reverted once the issues with the latest plugin
versions have been addressed.
epwalsh added a commit that referenced this issue May 31, 2024
* Only collect anchors/blocks when prompted in completion

Closes #589.

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

Successfully merging a pull request may close this issue.

2 participants