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

Custom empty message when no completion found #5158

Merged
merged 7 commits into from
May 11, 2023

Conversation

oykuyilmaz
Copy link
Contributor

@oykuyilmaz oykuyilmaz commented May 8, 2023

  1. Rebased Allow user feedback for empty autocompletes #4959.

Add support for setting a completer.emptyMessage function which
generates a message to display in the completions popup when there
are no completions.
This enables configuring the editor to always give the user feedback
when they ask for suggestions, even if it is just to note that there
are none.

  1. Allows users to pass a parent node to autocomplete popover (it was body).
  2. Makes doc-tooltips a child of autocomplete popover.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented May 8, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (5f2face) 86.94% compared to head (4fed371) 86.96%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5158      +/-   ##
==========================================
+ Coverage   86.94%   86.96%   +0.01%     
==========================================
  Files         560      561       +1     
  Lines       44220    44962     +742     
  Branches     6854     6913      +59     
==========================================
+ Hits        38446    39099     +653     
- Misses       5774     5863      +89     
Flag Coverage Δ
unittests 86.96% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/autocomplete.js 80.12% <100.00%> (+1.10%) ⬆️
src/autocomplete/popup.js 85.21% <100.00%> (+0.05%) ⬆️
src/autocomplete_test.js 99.34% <100.00%> (+0.06%) ⬆️
src/ext/language_tools.js 68.69% <100.00%> (ø)

... and 22 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@oykuyilmaz oykuyilmaz changed the title Custom empty message for no completion found Custom empty message when no completion found May 8, 2023
this.exactMatch = false;
this.inlineEnabled = false;
this.keyboardHandler = new HashHandler();
this.keyboardHandler.bindKeys(this.commands);
this.emptyMessage = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be better to not set this to null, to allow setting the function on prototype

return this.detach();

if (!filtered.length && this.emptyMessage && !this.autoShown) {
var completionsForEmpty = [{
caption: this.emptyMessage(prefix),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be shown merely based on existence of emptyMessage method or also on it returning a non-empty string?
Something like the following:

if (!filtered.length) {
    var emptyMessage = !this.autoShown && this.emptyMessage
    if ( typeof emptyMessage == "function")
          emptyMessage = this.emptyMessage(prefix);
     if (emptyMessage) { /*show completions code */}
     return this.detach();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the return.detach tho. If we detach directly, no popover is shown.

src/autocomplete.js Outdated Show resolved Hide resolved
@oykuyilmaz oykuyilmaz marked this pull request as ready for review May 10, 2023 12:35
Copy link
Member

@nightwing nightwing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but see two small comments.

src/autocomplete.js Show resolved Hide resolved
src/autocomplete.js Show resolved Hide resolved
@oykuyilmaz oykuyilmaz merged commit 204aafa into ajaxorg:master May 11, 2023
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.

3 participants