alienzhou / web-highlighter

✨ A no-runtime dependency lib for text highlighting & persistence on any website ✨🖍️
https://alienzhou.github.io/web-highlighter/
MIT License
890 stars 144 forks source link

highlighter.removeAll() doesn't work #27

Closed dannyChyang closed 4 years ago

dannyChyang commented 4 years ago

Version

0.3.3

Problem

highlighter.removeAll()API不起作用。追踪了代码,发现util/dom.ts 42 行getHighlightsByRoot()函数中没有返回concat后的新值。

export const getHighlightsByRoot = ($roots: HTMLElement | Array<HTMLElement>): Array<HTMLElement> => {
    if (!Array.isArray($roots)) {
        $roots = [$roots];
    }

    const $wraps = [];
    for (let i = 0; i < $roots.length; i++) {
        const $list = $roots[i].querySelectorAll(`${WRAP_TAG}[data-${DATASET_IDENTIFIER}]`);
        // $wraps.concat($list);
        $wraps.push.apply($wraps, $list);
    }
    return $wraps;
}
alienzhou commented 4 years ago

Merged. Thanks!