๐Ÿž Bug: Lists Break Org Indent At End of H3 Section and Beyond

#529 ยท closed ยท 12 comments

View on GitHub โ†—

vi6jm

### ๐Ÿค– Which branch are you using? - [ ] dev - [x] main ### ๐Ÿ“œ Issue description: Using the following causes the wrong indentation in various ways that are difficult to describe after an H3 heading is created (especially when that heading has no body). ```lua { headings = org_indent = true shift_width = 1 org_shift_width = 1 org_shift_char = " " } ``` --- The problem lies in two areas: 1. https://github.com/OXY2DEV/markview.nvim/blob/main/lua/markview/parsers/markdown.lua#L626 2. https://github.com/OXY2DEV/markview.nvim/blob/main/lua/markview/parsers/markdown.lua#L634 Both need 1 subtracted from them. So, **L626** would be `local org_end = range.row_end - 1;` and **L634** could have `org_end = org_end - 1;` after it, eg. --- I forked repo. I can submit PR in about 7 hours. ### ๐Ÿ“‘ Reproduction steps: I really don't feel like it, but I patched the bug locally ### ๐Ÿ’ป Minimal init: ... ### ๐Ÿ“œ Logs: ... ### Neovim version: v0.12.5 ### โœ… Expected behavior: Indentation indented correctly, as bug fixes detailed will do

Comments

OXY2DEV

> causes the wrong indentation in various ways that are difficult to describe You could've just sent a screenshot you know? @vi6jm And I am unable to reproduce your issue on my end.

vi6jm

True; apologies; work busy. I also fixed the table indentation issue just now @ lunch. Will open PR later for your consideration. Thanks for everything. <img width="1920" height="1080" alt="Image" src="https://github.com/user-attachments/assets/c874e520-d76b-43e8-baf7-b733355f2aa9" /> -vs- <img width="1920" height="1080" alt="Image" src="https://github.com/user-attachments/assets/759264b9-d709-4240-b5f0-d6fd03753312" /> edit: `:s/stard and end/end` note: even though last H4 heading is indented in the raw markdown, it's still indented 2 (or 3 even sometimes?) too many spaces in the rendered markdown too. <details> <summary>Here's the markdown file:</summary> ```markdown # Heading 1 - Bullet ## Heading 2 - Bullet ### Heading 3 - Bullets here ### Heading 3 --^--- indented 2 more than it should be here 1. Critically: a secondary bulleted/numbered *seemingly* list triggers the issue... if you stard and end with a list, it will pass the issue "downstream" ### Heading 3 --^--- indented 2 more than it should be here (again) - more bullets pass the issue downstream | Tables | Also | Ugly | | ------ | ---- | --- | foo | bar | qux - more bullets to pass issue downstream ## Heading 2 --^--- indented 2 more again - more bullets pass the issue downstream This body is indented correctly. ### Heading 3 - seems fine #### Heading 4 - seems fine #### Heading 4 --^--- this whole block is indented way too far, and the heading is indented 2 ... and now this line is deindented for some reason ... let's see what the next line ... yeah it is indented correctly as well ``` </details>

vi6jm

seems like you need to end the section with a bulleted or numbered list. I can investigate more if my fixes break other areas first. But I tentatively have a solution.

OXY2DEV

@vi6jm you have `wrap` enabled that's what's breaking the spacing before text. Neovim doesn't *yet* support adding decorations before wrapped lines, so the "indentation" gets drawn on the wrong spot. Until Neovim adds support for that this issue can't be reliably fixed. And no, you can't simply "guess"/"heuristic your way" into figuring out where text gets wrapped, without access to internal API it's impossible to reliably guess where text gets wrapped.

vi6jm

@OXY2DEV Really? ```vim :setl nowrap :Markview toggle :setf markdown :e :Markview toggle ``` doesn't seem to help. Thanks for looking into it, Vi

vi6jm

It's not just the table being indented weird - it's the bullets at the end of an H3 section and any following section that cause the heading to be indented by at least 2 more spaces than it should be. Min exampe: ```markdown # h1 - bullet ## h2 - bullet ### h3 - bullet ### h3 - bad indent - bullet - all following headings have 2+ extra spaces until the last inline markdown element is not a list. ```

vi6jm

ok nvm I will write my own markdown renderer / decorator. seems fun ^_^

vi6jm

just in case https://github.com/OXY2DEV/markview.nvim/compare/main...vi6jm:markview.nvim:main

vi6jm

With my changes, all correct as far as I can tell (even with `'wrap'` enabled ๐Ÿคทโ€โ™€๏ธ) <img width="996" height="1061" alt="Image" src="https://github.com/user-attachments/assets/0cf1c7f5-890e-4b6e-9874-f8b268d98ea4" />

OXY2DEV

I managed to reproduce the issue, it was a parsing mistake. It should be resolved now.

vi6jm

Cool; thanks. You left a `vim.print(range.org_end)` call in the main branch that prints a bunch of numbers on startup. I've started to look into supporting table virtual lines indenting correctly with org indent based on your recent commit. Looks like most places `config.use_virt_lines == true` you should use `string.rep(shift_char, math.max(0, shift_width * (item.level - 1)))` which you can "cache" in the exported table probably as `markdown.org_shift` .. probably like `table<int, string>` to cache shift amount and text. But it seems like maybe you feel differently about tables in org indent. For me with `use_virt_lines` they're indented 0 <img width="1920" height="1080" alt="Image" src="https://github.com/user-attachments/assets/57105d14-344d-4cf6-8b44-2dd208bba79d" /> <img width="1920" height="1080" alt="Image" src="https://github.com/user-attachments/assets/a99be5c5-d0e8-4d1a-be89-f72a674f9bac" />

vi6jm

PS, confirmation: org indent fixed for headings with lists now. Thanks again