Skip to content

TextQuoteSelector selector yielding an infinite number of matches #112

Open
@ziodave

Description

@ziodave

Hello,

Can you help me out, I tried to understand what's going on here: I created the following, which indeed works, i.e. the text is highlighted in DOM.

However it enters an infinite loop in for await (const match of matches) and I couldn't understand the cause:

async function highlightMatcher(matcher) {
  const matches = matcher(document.body);
  for await (const match of matches) {
    highlightRange(match); //    <----- this is called an infinite number of times
  }
}

const createMatcher = makeRefinable((selector) => {
  const innerCreateMatcher = {
    TextQuoteSelector: createTextQuoteSelectorMatcher,
    TextPositionSelector: createTextPositionSelectorMatcher,
    CssSelector: createCssSelectorMatcher,
    RangeSelector: makeCreateRangeSelectorMatcher(createMatcher)
  }[selector.type];
  if (!innerCreateMatcher) {
    throw new Error(`Unsupported selector type: ${selector.type}`);
  }
  return innerCreateMatcher(selector);
});

highlightMatcher(createMatcher({
  value: "#my-div",
  type: "CssSelector",
  refinedBy: {
    type: "TextQuoteSelector",
    exact: "My Text"
  }
}));

Metadata

Metadata

Assignees

No one assigned

    Labels

    🦟 BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions