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

Fix array index out of bounds on enter key event #773

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dreamofabear
Copy link

On keyboard enter, don't select when filteredItems is empty.

If filteredItems is empty array here:

if (this.tribute.isActive && this.tribute.current.filteredItems) {
e.preventDefault();
e.stopPropagation();
setTimeout(() => {
this.tribute.selectItemAtIndex(this.tribute.menuSelected, e);

Then item will be undefined here:

tribute/src/Tribute.js

Lines 473 to 479 in 252ec34

selectItemAtIndex(index, originalEvent) {
index = parseInt(index);
if (typeof index !== "number" || isNaN(index)) return;
let item = this.current.filteredItems[index];
let content = this.current.collection.selectTemplate(item);
if (content !== null) this.replaceText(content, originalEvent, item);
}

I noticed this when hitting the enter key on strings that don't match any values but coincidentally contain my trigger character, e.g. : in hyperlinks.

SrPatinhas added a commit to SrPatinhas/tribute that referenced this pull request Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant