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

Index wikilinks in frontmatter strings #1066

Merged
merged 1 commit into from
Oct 11, 2024

Conversation

Maarrk
Copy link
Contributor

@Maarrk Maarrk commented Aug 27, 2024

This implements #1000

The link is indexed only if it is the full content of a string node (allowing for quotes and whitespace) to discourage writing essays in the frontmatter 😄

I added an explanation why the quotes are needed on YAML page, I can't think of a page to document that the feature exists at all, I think it's discoverable by looking at indexPage in SETTINGS

@Maarrk
Copy link
Contributor Author

Maarrk commented Aug 27, 2024

Short demo of what it allows, credit to Raphwriter

Zrzut ekranu z 2024-08-27 13-31-38

Zrzut ekranu z 2024-08-27 13-33-07

@Maarrk
Copy link
Contributor Author

Maarrk commented Aug 27, 2024

Would be nice to make them clickable, but I think that becomes a much larger feature, since they shouldn't hide the [[ ]] like links in normal text do when cursor is away. Same for tags in frontmatter.

Considering #736 this would be almost like another editor mode when inside frontmatter: different widgets, different autocomplete etc., I don't know how I would approach that. Hope this bit here helps

@zefhemel
Copy link
Collaborator

zefhemel commented Aug 28, 2024

I have this test page:

---
another: "[[nice page]]"
---
This is a nice page [[nice page]]!

```query
link where page = @page.name
```

I would expect 2 entries in link, one for the regular page link and one for the frontmatter. And sometimes I get this, but not always. I make a small edit, let it save and Alt-q and it's there, and sometimes it's not. Do you have any idea what could be going on here? Some sort of race condition?

Then, when I rename another page I would expect both these links to be updated, but that's also not happening. Perhaps it's related to this indexing not happening consistently though... Can you replicate this?

@Maarrk
Copy link
Contributor Author

Maarrk commented Aug 30, 2024

Funnily enough, it did work in a small test space, but in my main one, I can't get the frontmatter mention to show up at all. I will look into it more these days, thanks for the heads up 👍

@Maarrk Maarrk force-pushed the pr-index-frontmatter-links branch from c84d2cd to 8ca9cd7 Compare October 9, 2024 20:12
@Maarrk
Copy link
Contributor Author

Maarrk commented Oct 9, 2024

Sorry for the delay, but the error was actually quite inconsistent to replicate. At the end I found it's a problem when reusing a Regex object with a global flag for multiple .exec() calls.

References:
https://stackoverflow.com/a/4724920/8531075
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex


There are multiple places in the codebase with someImportedRegex.exec(text). When the const object is actually created is not obvious (at least for me). It's possible that every call site like this should have someImportedRegex.lastIndex = 0 before, for general reliability improvement. Recreating the Regex everytime makes more sense, but is probably slower.

@Maarrk Maarrk force-pushed the pr-index-frontmatter-links branch from 8ca9cd7 to 96d489c Compare October 9, 2024 22:07
@zefhemel
Copy link
Collaborator

Seems to work as advertised now. Thanks!

@zefhemel zefhemel merged commit 7b955ef into silverbulletmd:main Oct 11, 2024
1 check passed
@zefhemel
Copy link
Collaborator

And interesting that these regexes are indeed stateful, I don't like that. It may indeed be better not to define them as globals in that case... Labeling them as const makes this even more confusing.

@Maarrk Maarrk deleted the pr-index-frontmatter-links branch October 14, 2024 17:48
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

Successfully merging this pull request may close these issues.

2 participants