Skip to content

feature: avoid inline text for checkboxes to maintain cursor position #378

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

Closed
2 tasks done
sand4rt opened this issue Mar 24, 2025 · 1 comment
Closed
2 tasks done
Labels
enhancement New feature or request

Comments

@sand4rt
Copy link

sand4rt commented Mar 24, 2025

Neovim version (nvim -v)

0.10.4

Neovim distribution

N/A

Operating system

Any

Terminal emulator / GUI

Any

Describe the bug

The cursor does not keep the correct position when moving down a list of checkboxes:

- [ ] boop
- [ ] boop
- [ ] boop
- [ ] boop
- [ ] boop
  1. place the cursor inside [ ]
  2. move down a line with j

the cursor is at [ instead of inside [ ]

Expected behavior

To keep the correct cursor position when moving down the list of checkboxes

Healthcheck output

N/A

Plugin configuration

{
        "MeanderingProgrammer/render-markdown.nvim",
        opts = {
            checkbox = {
                unchecked = {
                    icon = "󰄱",
                },
                checked = {
                    icon = "󰱒",
                },
            },
        },
        ft = { "markdown", "norg", "rmd", "org", "codecompanion" },
        config = function(_, opts)
            require("render-markdown").setup(opts)
        end,
    },

Plugin error log

N/A

Confirmations

  • I have updated this plugin to the latest version using my plugin manager
  • I have provided the text contained in all screenshots as raw text in this issue. This means if there is a screenshot below it is the copy pasted contents of the file in the screenshot. I understand that my issue will be closed if I have not.

Additional information

No response

@sand4rt sand4rt added the bug Something isn't working label Mar 24, 2025
@sand4rt sand4rt changed the title bug: checkboxes do not keep their cursor position when entering insert mode bug: checkboxes do not keep their cursor position Mar 24, 2025
@MeanderingProgrammer MeanderingProgrammer added enhancement New feature or request and removed bug Something isn't working labels Mar 24, 2025
@MeanderingProgrammer MeanderingProgrammer changed the title bug: checkboxes do not keep their cursor position feature: avoid inline text for checkboxes to maintain cursor position Mar 24, 2025
MeanderingProgrammer added a commit that referenced this issue Mar 24, 2025
## Details

Request: #378

Previously checkboxes were rendered by concealing the underlying text
and inlining the icon as virtual text. This works but would mess with
the cursor positions while scrolling due to how neovim handles showing
and hiding inline virtual text.

To avoid this we now use information about the amount of space available
to us, i.e. the width of the text in square brackets compared to the
width of the icon we are rendering, to add more clever marks.

Only when the icon is larger than the space available do we do the same
thing as before and fully conceal + inline.

Otherwise we use overlay virtual text to show the icon and conceal any
underlying text that extends under the icon (if any). When doing this we
also take into account the new `checkbox.right_pad` option (default
value 1), and similarly attempt to use the space available for the
padding. If the padding extends outside the available space then the
remaining amount is added as inline virtual text, requires neovim >=
`0.10.0` to work. The default value of 1 is chosen so that the rendered
text looks identical in most cases to before, since we now treat the
space after the checkbox as space available to us.

### Related Impacts

To maintain parity with how checked and unchecked checkboxes are handled
by `markdown`, we now require that there is a space following custom
states. This allows us to better determine exactly how much space we
have to work with.

The `checkbox.position` configuration option was removed. We now infer
how to display checkboxes best based on the space available to us and
the icon we are about to show. Any potential differences in how things
are displayed, can likely be changed back by using the new
`checkbox.right_pad` option. Most users should not see any differences.
Any users of `checkbox.position` should simply remove it from their
configuration, keeping it is fine, it just doesn't do anything.

Custom checkbox states will now work for versions of neovim older than
`0.10.0`, but since the plugin as a whole still requires `0.9.0` at a
minimum this only adds a couple supported versions for that specific
feature, and there are some limitations to its usage.
@MeanderingProgrammer
Copy link
Owner

Implemented better checkbox rendering here: f9badfb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants