const data = {
image: pngData,
- uploaded_to: Number(this.pageId),
+ uploaded_to: Number(this.editor.config.pageId),
};
window.$http.post("/images/drawio", data).then(resp => {
const scroll = this.editor.cm.getScrollInfo();
const atEnd = scroll.top + scroll.clientHeight === scroll.height;
if (atEnd) {
- editor.display.scrollToIndex(-1);
+ this.editor.display.scrollToIndex(-1);
return;
}
const parser = new DOMParser();
const doc = parser.parseFromString(this.editor.markdown.render(range), 'text/html');
const totalLines = doc.documentElement.querySelectorAll('body > *');
- editor.display.scrollToIndex(totalLines.length);
+ this.editor.display.scrollToIndex(totalLines.length);
}
/**
const cursorPos = this.editor.cm.coordsChar({left: event.pageX, top: event.pageY});
this.editor.cm.setCursor(cursorPos);
for (const image of images) {
- editor.actions.uploadImage(image);
+ this.editor.actions.uploadImage(image);
}
}
}
\ No newline at end of file
cm.on('change', (instance, changeObj) => editor.actions.updateAndRender());
// Handle scroll to sync display view
- const onScrollDebounced = debounce(editor.actions.syncDisplayPosition, 100, false);
+ const onScrollDebounced = debounce(editor.actions.syncDisplayPosition.bind(editor.actions), 100, false);
cm.on('scroll', instance => onScrollDebounced(instance));
// Handle image paste
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'});