-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Conversation
Codecov ReportPatch coverage:
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
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
src/autocomplete.js
Outdated
this.exactMatch = false; | ||
this.inlineEnabled = false; | ||
this.keyboardHandler = new HashHandler(); | ||
this.keyboardHandler.bindKeys(this.commands); | ||
this.emptyMessage = null; |
There was a problem hiding this comment.
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
src/autocomplete.js
Outdated
return this.detach(); | ||
|
||
if (!filtered.length && this.emptyMessage && !this.autoShown) { | ||
var completionsForEmpty = [{ | ||
caption: this.emptyMessage(prefix), |
There was a problem hiding this comment.
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();
}
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
body
).By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.