mProjectsCode / obsidian-shiki-plugin

MIT License
43 stars 6 forks source link

Losing focus on the current document while editing a block of code results in incorrect scrolling #24

Open tp1415926535 opened 1 month ago

tp1415926535 commented 1 month ago

Describe the bug When the code block is in the editing state, if you switch to another page or browser or something, come back to obsidian and find that the document scrolling is heavily offset. And without using this plugin this problem does not occur, because you can edit the code block directly. It may be that the current document loses focus and then changes back to a block that cannot be edited, and then enters the editing state when focus is restored, but does not return to the original position.

To Reproduce Steps to reproduce the behavior:

  1. Write a long block of code.
  2. Entering the editing state of a code block and scroll down a bit.
  3. Open your browser.
  4. Back to Obsidian page.

Expected behavior Revert to the original scroll offset.

Screenshots If applicable, add screenshots to help explain your problem.

Occurs on

Plugin version 0.4.3

Additional context The other thing that confuses me is that, in the code block editing state, it is often the original syntax highlighting colour, while there are only a few cases where the preview state syntax highlighting can be displayed.

mProjectsCode commented 1 month ago

The scroll issue is caused by how Obsidian handles code block post processors. I don't think there is anything I can do about it.

The original highlighting showing happens on large code blocks, as Obsidian hides the parts of the note that are not visible and the plugin requires the entire code block to be "loaded" for it to be able to do syntax highlighting.

mProjectsCode commented 1 month ago

I am also not updating highlights on scroll for performance reasons. Maybe something can still be improved there.

tp1415926535 commented 1 month ago

The scroll issue is caused by how Obsidian handles code block post processors. I don't think there is anything I can do about it.

Is it possible to prevent a block of code from exiting from the editing state when the note loses focus?

mProjectsCode commented 1 month ago

no, not afaik

mProjectsCode commented 4 weeks ago

oops, mentioned the wrong issue in that commit