BUGFIX: scroll sync messing with loose lists

This commit is contained in:
Sam 2014-04-07 10:51:15 +10:00
parent af6e376ee3
commit f7644e2cdf

View File

@ -920,8 +920,8 @@
return { return {
scrollerStart: markerPositions.scroller[startMarkerIndex], scrollerStart: markerPositions.scroller[startMarkerIndex],
scrollerEnd: markerPositions.scroller[endMarkerIndex], scrollerEnd: markerPositions.scroller[endMarkerIndex],
previewStart: markerPositions.preview[startMarkerIndex], previewStart: markerPositions.preview[startMarkerIndex] || markerPositions.preview[markerPositions.preview.length-1],
previewEnd: markerPositions.preview[endMarkerIndex] previewEnd: markerPositions.preview[endMarkerIndex] || markerPositions.preview[markerPositions.preview.length-1]
}; };
}; };
@ -974,7 +974,6 @@
// Adds event listeners to elements // Adds event listeners to elements
var setupEvents = function (inputElem, listener) { var setupEvents = function (inputElem, listener) {
util.addEvent(inputElem, "input", listener); util.addEvent(inputElem, "input", listener);
inputElem.onpaste = listener; inputElem.onpaste = listener;
inputElem.ondrop = listener; inputElem.ondrop = listener;
@ -1025,20 +1024,32 @@
if (scrollSyncOn) { if (scrollSyncOn) {
var caretPosition = getCaretPosition(); var caretPosition = getCaretPosition();
text = text.slice(0, caretPosition) + '~~caret~~' + text.slice(caretPosition);
text = text.replace(/(\n|\r|\r\n)(\n|\r|\r\n)+/g, "$&~~marker~~$1$1");
previewText = converter.makeHtml(text.replace('~~caret~~', '')) var caret = "465c94fb53b6304c4f57";
.replace(/<p>~~marker~~<\/p>/g, '<span class="marker"></span>') var marker = "468c94fb53b6304c4f58";
.replace(/~~marker~~/g, '<span class="marker"></span>');
previewScrollerText = text // add last marker
text = text + marker;
var addMarkers = function(text) {
return text.replace(/(\s*)(\n|\n|\r|\r\n)/g, function(m, spaces, newline) {
return marker + spaces + "\n";
});
}
previewText = converter.makeHtml(addMarkers(text))
.replace(new RegExp(marker, 'g'), '<span class="marker"></span>');
var withCaret = text.slice(0, caretPosition) + caret + text.slice(caretPosition);
previewScrollerText = addMarkers(withCaret)
.replace(/&/g, '&amp;') .replace(/&/g, '&amp;')
.replace(/</g, '&lt;') .replace(/</g, '&lt;')
.replace(/>/g, '&gt;') .replace(/>/g, '&gt;')
.replace(/(\n|\r|\r\n)/g, '<br>') .replace(/(\n|\n\r|\r\n)/g, '<br>')
.replace('~~caret~~', '<span class="caret"></span>') .replace(caret, '<span class="caret"></span>')
.replace(/~~marker~~<br><br>/g, '<span class="marker"></span>'); .replace(new RegExp(marker, 'g'), '<span class="marker"></span>');
} else { } else {
previewText = converter.makeHtml(text); previewText = converter.makeHtml(text);
} }