} else {
this.container.addEventListener('load', this.onLoad.bind(this));
}
+
+ this.updateVisibility(editor.settings.get('showPreview'));
+ editor.settings.onChange('showPreview', show => this.updateVisibility(show));
+ }
+
+ updateVisibility(show) {
+ const wrap = this.container.closest('.markdown-editor-wrap');
+ wrap.style.display = show ? null : 'none';
}
onLoad() {
this.doc.body.className = 'page-content';
// Prevent markdown display link click redirect
- this.doc.addEventListener('click', this.onDisplayClick)
+ this.doc.addEventListener('click', this.onDisplayClick.bind(this));
}
/**
* @param {Number} index
*/
scrollToIndex(index) {
- const elems = this.doc.body.children;
- if (elems.length <= index) return;
+ const elems = this.doc.body?.children[0]?.children;
+ if (elems && elems.length <= index) return;
const topElem = (index === -1) ? elems[elems.length-1] : elems[index];
topElem.scrollIntoView({ block: 'start', inline: 'nearest', behavior: 'smooth'});