codexa / firetext

[NOT MAINTAINED] Word Processing App 📝 📖

Home Page:https://marketplace.firefox.com/app/firetext

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chrome desktop hangs on generating document preview

twiss opened this issue · comments

Chrome hangs at https://github.com/codexa/firetext/blob/87e5b12/scripts/firetext.js#L428 trying to generate a preview for relatively simple documents, e.g. (but not for documents even simpler):

Hoi ik ben <b>Daniel</b>!<div>Test</div><div>Test</div><div>Test</div><div>Test</div><div>Test bladibla</div><div><br><br></div><div>Hoi,&nbsp;<i>ik</i>&nbsp;ben Daniel.</div>

I'm not sure why I've never noticed this before, or what caused it if this is new.

Hmm, the preview generation code is quite complicated. I have actually toyed with the idea of removing it altogether (or at least rewriting it). My guess is that the text is so long that comparing it to a regular expression is simply too much for the JS engine.

Alright. Alternatively, if I understand the current code correctly, you could do something like (not tested)

for(var i = 0, j = 0, inTag = false; i < text.length && j < textTruncated.length; i++) {
    if(text[i] === '<') {
        inTag = true;
    } else if(text[i] === '>') {
        inTag = false;
    } else if(!inTag) {
        j++;
    }
}
var htmlOfTextWanted = text.substr(0, i);

Closed by #320.