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

Allow styling matched substrings in the completion dropdown #234

Closed
juliusv opened this issue Jul 9, 2020 · 7 comments
Closed

Allow styling matched substrings in the completion dropdown #234

juliusv opened this issue Jul 9, 2020 · 7 comments

Comments

@juliusv
Copy link

juliusv commented Jul 9, 2020

It would be really cool to be able to highlight / make bold the parts of the completion item that are already matched by the typed string. Like this, in Monaco:

autocomplete-highlight

@marijnh
Copy link
Member

marijnh commented Jul 10, 2020

My judgement, so far, is that this isn't all that useful (the fact that an item matches is the useful information,how it matched isn't terribly important), and makes it hard to allow things like completion-source-level filtering and displaying labels that aren't precisely identical to the matched string. But if you want to make a case for why this is important, I'm interested in hearing it.

@juliusv
Copy link
Author

juliusv commented Jul 10, 2020

One argument is just the subjective "it's pretty and everyone does it", but a more useful one might be that it sometimes helps me find the right completion item faster. Often (with fuzzy matching) I am only looking for items that contain the typed substring either at the beginning, the end, or somewhere in the middle. Highlighting the matched substring(s) helps me to skip over / ignore the irrelevant items more quickly.

@Nexucis
Copy link

Nexucis commented Aug 4, 2020

A compromise if you are not interested could be to just provide another implementation of autocompletePlugin that handle this problem.

And then it will be up to the user to activate it.

So far I didn't get how to change it, and also I supposed that ViewPlugin will have to know how the text has been filtered. Sounds quite complicate ....

But anyway would you be opened to have it ? From my point of view, it will be pretty cool that CodeMirror is providing it. It's quite weird to not have it actually since like Julius said, everybody does it. But really everybody, even your IDE is doing it.

And basically when you have it, usually you don't pay particular attention, but because it's usual to have it. Your eyes is used to have it. And I'm agree with Julius on the fact that it helps a lot to find what you are looking for. Specially when the fuzzy filtering is activated.
For other mode, since it's quite obvious how the text is matched, yes you don't really need it, but for the fuzzy it's important. It helps a lot to highlight the word you are typing, specially when each letters are separated by others noisy letter like
word is matching we have the opportunity to change the world. Would take a wild to see the term word in this sentence without the bold characters.

@Nexucis
Copy link

Nexucis commented Aug 7, 2020

Actually I found something much simpler.

So the idea would be to allow the user to put some html in the field Completion.label
Today when you are trying that, here the result you have:

image

And when you are looking at the HTML, it looks like that the string <b>p</b>ush has been encoded. In the HTML you have this:

&lt;b&gt;p&lt;/b&gt;ush

So if the system wouldn't encode the string, then the problem would be solved. Am I missing something in this picture ?

@Nexucis
Copy link

Nexucis commented Aug 7, 2020

@Nexucis
Copy link

Nexucis commented Aug 7, 2020

which could be changed like that:

    const className = themeClass("completionIcon" + (completion.type ? "." + completion.type : ""))
    li.innerHTML = '<div class="'+className+'"></div>' + completion.label
    li.setAttribute("role", "option")

image

But maybe there is a more elegant way to do it.

@marijnh
Copy link
Member

marijnh commented Aug 24, 2020

Since everybody seems to like this feature, and completion filtering had to be moved into the library to allow more refined scoring anyway, I've implemented this in 0547455...fc352af

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