Line Number for Code Block

What I’m trying to do

When we have a code block that goes longer than one visible page, then the line / row numbers for the code block behaves weird. The line numbers either turn to 1 after first visible page, or they reset again and again with each scroll instead of continuing.

This happens in all the themes where line numbers are shown for a code block. No further snippets or any modification is running on my vault. This is default settings with just themes added from the store.

Theme: AnuPpuccin

Scroll 1:

Scroll 2:

Theme: Shimmering Focus

Scroll 1:

Scroll 2:

Theme: Maple

Scroll 1:

Scroll 2:

Scroll 3:

Scroll 4:

Observation

If you see the screenshots for theme Maple, then with every two scrolls, the content that was loaded previously is lost from view and is also lost from memory based on which the line numbers may be calculated. And that’s why, the line numbers reset. So, even though the total lines for this json file is 227, still the lines will never go beyond ~75 in my case, as by the time it reaches that number, the previous lines are lost from view and memory and the number again begins from 30 or so, with one previous page-up still in memory.

I hope I am making some sense as this is so difficult to explain without a video.

Please ask if you need further information

How do I solve this? Is this a bug?

Theme: AnuPpuccin (Numbers freezes to 1 after first page scroll)

Theme: Shimmering Focus (Numbers freezes to 1 after first page scroll)

Theme: Maple (Numbers reset after first page scroll)

Scroll 2: (Notice how line 33 in scroll 1 "name": "... becomes line 30 after scroll 2)
Scroll 3: (Notice how line 59 in scroll 2 "about": "Velit..." becomes line 40 after scroll 3)
Scroll 4: (Notice how line 76 in scroll 3 "picture":... becomes line 31 after scroll 4)

I would guess this is the theme bug as it looks like a counter problem. But, it could also be some CSS snippet playing with theme settings.

My suggestions:

  1. Try to disable CSS snippets. Maybe all, and if fix the problem, turn them slowly on one by one to see which one is causing the problem.
  2. Report a bug to the theme owner; I don’t think that is an Obsidian issue.

Cheers, Marko :nerd_face:

I think the issue is that, to maintain performance, Obsidian doesn’t render the whole file. Things far above and below the current position aren’t rendered. When the top part of the big code block goes outside the rendering window, its lines are no longer available to be counted by the CSS. (You can see a similar problem when people apply rainbow coloring to the file browser; the colors shift when the top of the file list scrolls out of the rendering window.)

2 Likes

I’ve never built a theme for an Obsidian, but when I’m having similar issues in some modules (web app) and, due to performance, I do not render all the lines, I create a JS/TS counter script, which helps me track and continue counter-set properties.

And as an Obsidian setting, Show line numbers is working, and thinking that theme-building-kit uses something like this, I was hoping that some snippet is preventing continuous counting :smiley:

But yes, I agree with @CawlinTeffid that render is the problem.

Cheers, Marko :nerd_face: