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

positionMenu will cause JS promise error when use multiword and promise for provide #71

Open
wxiaoguang opened this issue Jan 25, 2025 · 0 comments

Comments

@wxiaoguang
Copy link

wxiaoguang commented Jan 25, 2025

Stacktrace:

Uncaught (in promise) IndexSizeError: Failed to execute 'setStart' on 'Range': The offset 28 is larger than the node's length (27).
    at #createCloneRange
    at InputRange.getBoundingClientRect
    at TextExpander.positionMenu
    at TextExpander.activate
    at TextExpander.onInput

It seems that 2 bugs are related:

  1. when provide a promise, after await Promise.all(providers), the textarea's content might have changed.

But activate and positionMenu still use old (outdated) match, then the position in const caretRect = new InputRange(this.input, position).getBoundingClientRect(); is invalid.

  1. the query will return incorrect position for "multiword" when the last "key" is removed.

To reproduce:

<text-expander multiword="#">...</>

provide(async () => {
    await sleep(Math.random() * 1000); 
    return {matched: true .....};
});

Then use the textarea value:

close #20
close #20 
close #20

And delete the chars in the last line from the end, when the # in the last line is deleted, the JS error occurs. It's quite strange that it must have 3 lines to reproduce the bug.

@wxiaoguang wxiaoguang closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2025
@wxiaoguang wxiaoguang changed the title positionMenu will cause JS promise error when provide uses promise positionMenu will cause JS promise error when use multiword and promise for provide Jan 25, 2025
@wxiaoguang wxiaoguang reopened this Jan 25, 2025
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

1 participant