Skip to content

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

Open
@wxiaoguang

Description

@wxiaoguang

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions