simplify createSideBySide

pull/510/head
WittBulter 7 years ago
parent 2a07108c23
commit f4228c8397

@ -318,8 +318,9 @@ class SimpleMDE extends Action {
let cm = this.codemirror; let cm = this.codemirror;
let wrapper = cm.getWrapperElement(); let wrapper = cm.getWrapperElement();
let preview = wrapper.nextSibling; let preview = wrapper.nextSibling;
const notCreate = !preview || !/editor-preview-side/.test(preview.className)
if(!preview || !/editor-preview-side/.test(preview.className)) { if(notCreate) {
preview = document.createElement("div"); preview = document.createElement("div");
preview.className = "editor-preview-side"; preview.className = "editor-preview-side";
wrapper.parentNode.insertBefore(preview, wrapper.nextSibling); wrapper.parentNode.insertBefore(preview, wrapper.nextSibling);
@ -331,8 +332,8 @@ class SimpleMDE extends Action {
cm.on("scroll", v => { cm.on("scroll", v => {
if(cScroll) return cScroll = false; if(cScroll) return cScroll = false;
pScroll = true; pScroll = true;
let height = v.getScrollInfo().height - v.getScrollInfo().clientHeight; const height = v.getScrollInfo().height - v.getScrollInfo().clientHeight;
let ratio = parseFloat(v.getScrollInfo().top) / height; const ratio = parseFloat(v.getScrollInfo().top) / height;
preview.scrollTop = (preview.scrollHeight - preview.clientHeight) * ratio; preview.scrollTop = (preview.scrollHeight - preview.clientHeight) * ratio;
}); });
@ -340,9 +341,9 @@ class SimpleMDE extends Action {
preview.onscroll = () => { preview.onscroll = () => {
if(pScroll) return pScroll = false; if(pScroll) return pScroll = false;
cScroll = true; cScroll = true;
let height = preview.scrollHeight - preview.clientHeight; const height = preview.scrollHeight - preview.clientHeight;
let ratio = parseFloat(preview.scrollTop) / height; const ratio = parseFloat(preview.scrollTop) / height;
let move = (cm.getScrollInfo().height - cm.getScrollInfo().clientHeight) * ratio; const move = (cm.getScrollInfo().height - cm.getScrollInfo().clientHeight) * ratio;
cm.scrollTo(0, move); cm.scrollTo(0, move);
}; };
return preview; return preview;

Loading…
Cancel
Save