Closed walulula closed 3 years ago
I took a deeper look at the code and found the cause to be Obsidian unexpectedly changing the padding-bottom value of the CodeMirror-lines class. Overwriting padding-bottom through the onRefresh function fixes the problem for me.
function onRefresh(cm) {
const halfWindowHeight = cm.getWrapperElement().offsetHeight / 2;
const linesEl = cm.getScrollerElement().querySelector('.CodeMirror-lines');
linesEl.style.paddingTop = `${halfWindowHeight}px`;
linesEl.style.paddingBottom = `${halfWindowHeight}px`; // This line fixes the jumping
if (cm.getSelection().length === 0) {
cm.execCommand("scrollSelectionToCenter");
}
}
Yup. I was having that problem and this fixed it.
Thanks.
macosxguru
Thanks for the fix! I noticed it wasn't just jumping a line at random. It effectively seemed to be overriding the line-centering, so that as long as you continued typing in the current paragraph (i.e. same line without a return carriage), you would get closer and closer to the bottom, until you reached the bottom, and stayed there. It effectively makes it feel like typewriter mode has been completely disabled until you hit
Anyway the above fix works perfectly.
Thank you so much for this plugin. It really helps me to focus on my writing.
Sadly I encountered a bug that occurs sometimes when breaking into a new line.