parpalak / upmath.me

Markdown and LaTeX online editor - create text for web with equations and diagrams
https://upmath.me/
MIT License
323 stars 40 forks source link

supporting multiple parserCollection in a page #19

Closed sajozsattila closed 11 months ago

sajozsattila commented 4 years ago

When having multiple parserCollection on one page the ImageLoader in the parserCollection is always the last which was initialized. The reason for this I belive the:

varupdateText=debounce(parserCollection.updateResult,300,{maxWait: 3000});

In my project, I have worked around the issue with rewriting the updateResult:

this.updateResult=function(imageLoader){
}

And I pass the ImageLoader every time to the:

varupdateText(ImageLoader )

See (search for updateMain )

parpalak commented 4 years ago

Well, what is your exact question?

In my version of code every instance of ParserCollection corresponds to an editor. If you have several editors on a single page, you have to instantiate several parser collections and supply every parser collection with its own ImageLoader instance.

sajozsattila commented 4 years ago

Unfortunately, it is not true. Because of the debounce. When you have multiple ParseCollection you can use an example:

var imageLoader1 = New ImageLoader();
var imageLoader2 = New ImageLoader();
var parserCollection1 = new  parserCollection ( .. imageLoader1  ... )... ;
var parserCollection2 = new  parserCollection ( .. imageLoader2  ... )... ;

// make update
parserCollection1.updateResult();
parserCollection2.updateResult();

The above is work.

But if you do:

varupdateText1=debounce(parserCollection1.updateResult,300,{maxWait: 3000});
varupdateText2=debounce(parserCollection2.updateResult,300,{maxWait: 3000});

Some reason the varupdateText1 will use the parserCollection2 imageLoader.

sajozsattila commented 4 years ago

Other problem with the multiple parserCollection: the ImageLoader have hardcoded prefix ('s2tex_'), which make so you are ending up with multiple 'id="s2tex_0"' etc. in your page. And as you use ID to load them in the utils:

    function insertPicture(index, svg, baselineShift, mode) {
        var id = 's2tex_' + index,
            oldSvgNode = document.getElementById(id),

So probably could be a good idea, if you add a prefix setting possibility to the ImageLoader.

parpalak commented 11 months ago

Unfortunately, I haven't had a chance to look at the problem until now. Maybe I'll come back to it if I do some refactoring. For now, I'm closing the issue as outdated. If there was a pull-request with a possible solution, I'd love to see it and accept it.