antonk52 / markdowny.nvim

Markdown like keymaps for toggling text formatting
73 stars 7 forks source link

Add checkbox toggle #12

Closed EricDriussi closed 2 months ago

EricDriussi commented 2 months ago

Hello!

Fiddling around with my config I ended up writing a function to toggle (check/uncheck) a checkbox (- [ ]).

It might be useful to add the functionality to this plugin, currently my function looks something like this:

local function toggle_checkbox()
    local line = vim.api.nvim_get_current_line()
    local line_has_checkbox = string.match(line, "^%s*- %[[%sXx]%]")

    if line_has_checkbox then
        local is_checked = string.match(line, "%[[xX]%]")
        if is_checked then
            local new_line = string.gsub(line, "%[[xX]%]", "[ ]", 1)
            vim.api.nvim_set_current_line(new_line)
        else
            local new_line = string.gsub(line, "%[%s%]", "[x]", 1)
            vim.api.nvim_set_current_line(new_line)
        end
    end
end

It's not pretty and doesn't handle visual mode. There is surely a better implementation but it might be a good starting point.

antonk52 commented 2 months ago

Thanks for the interest. I have something similar in my own configuration.

I think this falls outside of the scope for this plugin. Perhaps this will be a welcome change to a more generic markdown plugin.