obsidian-shiki-plugin icon indicating copy to clipboard operation
obsidian-shiki-plugin copied to clipboard

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

Open tp1415926535 opened this issue 1 year ago • 5 comments

  • [x] The Plugin is up to date
  • [x] Obsidian is up to date

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

  • [x] Windows
  • [ ] macOS
  • [ ] Linux
  • [ ] Android
  • [ ] iOS

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.

tp1415926535 avatar Sep 19 '24 02:09 tp1415926535

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 avatar Sep 19 '24 08:09 mProjectsCode

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

mProjectsCode avatar Sep 19 '24 08:09 mProjectsCode

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?

tp1415926535 avatar Sep 19 '24 09:09 tp1415926535

no, not afaik

mProjectsCode avatar Sep 19 '24 09:09 mProjectsCode

oops, mentioned the wrong issue in that commit

mProjectsCode avatar Sep 20 '24 16:09 mProjectsCode