Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected line jumping #6

Closed
walulula opened this issue Feb 12, 2021 · 3 comments
Closed

Unexpected line jumping #6

walulula opened this issue Feb 12, 2021 · 3 comments

Comments

@walulula
Copy link

@walulula walulula commented Feb 12, 2021

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.

Kapture 2021-02-12 at 21 39 45s

@walulula
Copy link
Author

@walulula walulula commented Feb 14, 2021

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");
    }
}

@macosxguru
Copy link

@macosxguru macosxguru commented Feb 14, 2021

Yup. I was having that problem and this fixed it.

Thanks.

macosxguru

@frankreporting
Copy link

@frankreporting frankreporting commented Apr 3, 2021

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 to create a new line. Then it finally snaps back to center. So this bug was most noticeable on very long paragraphs.

Anyway the above fix works perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants