wickedest / Mergely

Merge and diff documents online
http://www.mergely.com
Other
1.17k stars 228 forks source link

Replacing text with shorter text while scrolled down throws an uncaught error #69

Closed clovetea closed 7 years ago

clovetea commented 7 years ago

On the demo page, http://www.mergely.com/editor, open the console and run these lines to populate the editors.

$('#mergely').mergely('lhs', Array(100).join("This is a test 1\n"));
$('#mergely').mergely('rhs', Array(100).join("This is a test 2\n"));

It should scroll to the bottom. While scrolled to the bottom, run this line

$('#mergely').mergely('lhs', Array(10).join("This is a test 3\n"));

It will throw this error

mergely.min.js:6 Uncaught TypeError: Cannot read property 'replace' of undefined
    at new Mgly.LCS (mergely.min.js:6)
    at Mgly.CodeMirrorDiffView._markup_changes (mergely.min.js:7)
    at Mgly.CodeMirrorDiffView._scrolling (mergely.min.js:6)
    at mergely.min.js:6
    at CodeMirror.signal (codemirror.min.js:7)
    at HTMLDivElement.<anonymous> (codemirror.min.js:3)

The error only seems to be thrown if the new text doesn't reach the point the editor is currently scrolled to. I've reproduced this in Chrome and Firefox. The above error message is from Chrome. The issue in my use case is that this is then getting caught by the window.onerror handler, leading to a warning that an operation has failed.

wickedest commented 7 years ago

Thanks for the clear example. PR here: https://github.com/wickedest/Mergely/pull/70. I'll cut a new release with the patch.

clovetea commented 7 years ago

That's great, thanks for the quick response!