autolist.nvim icon indicating copy to clipboard operation
autolist.nvim copied to clipboard

AutolistRecalculate does not function correctly on indented ordered lists.

Open CabalCrow opened this issue 1 year ago • 1 comments

Tested in a markdown file: AutolistRecalculate does not recalculate correctly ordered list if it lacks the first element. For example

1. list
2. list
3. list

if the 3. element of the list is indented & then AutolistRecalculate is used this is the list I get:

1. list
2. list
    3. list

instead of:

1. list
2. list
    1. list

Indenting back into an indent level where you have a 1. (or any other first element of an ordered list) & then using AutolistRecalculate does work correctly, example:

1. list
2. list
3. list
    1. list
    2. list
        5. list 

You can indent the last element of the list either to the first level (which will recalculate to 4) or the second level (which would recalculate to 3). However if the 1. is missing on the second level it won't recalculate the whole second level from its first element like it would on the initial indent, example:

1. list
    2. list
        5. list 

if we indent back into the second level with the final element:

1. list
    2. list
    3. list 

instead of:

1. list
    1. list
    2. list 

Also using AutolistCycleNext (or prev) on an indended order list with missing first element (the same type of list where recalculate does not work correctly on) does nothing at all. Also treesitter does not colour that list (it colours the list in which those commands function correctly) so don't know if that could be related.

This is my config:

{
        "gaoDean/autolist.nvim",
        ft = {
            "markdown",
            "text",
            "tex",
            "plaintex",
            "norg",
        },
        config = function()
            require("autolist").setup()

            vim.keymap.set("i", "<c-t>", "<c-t><cmd>AutolistRecalculate<cr>") -- an example of using <c-t> to indent
            vim.keymap.set("i", "<c-d>", "<c-d><cmd>AutolistRecalculate<cr>") -- an example of using <c-t> to indent
            vim.keymap.set("i", "<CR>", "<CR><cmd>AutolistNewBullet<cr>")
            vim.keymap.set("n", "o", "o<cmd>AutolistNewBullet<cr>")
            vim.keymap.set("n", "O", "O<cmd>AutolistNewBulletBefore<cr>")
            vim.keymap.set("n", "<CR>", "<cmd>AutolistToggleCheckbox<cr><CR>")

            -- cycle list types with dot-repeat
            vim.keymap.set("i", "<c-tab>", require("autolist").cycle_next_dr, { expr = true })
	    vim.keymap.set("i", "<c-s-tab>", require("autolist").cycle_prev_dr, { expr = true })
            vim.keymap.set("n", "<leader>an", require("autolist").cycle_next_dr, { expr = true })
            vim.keymap.set("n", "<leader>ap", require("autolist").cycle_prev_dr, { expr = true })

            -- functions to recalculate list on edit
            vim.keymap.set("n", ">>", ">><cmd>AutolistRecalculate<cr>")
            vim.keymap.set("n", "<<", "<<<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("n", "nn", "dd<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("n", "<leader>n", "dd<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("n", "<leader><backspace>", "\"_dd<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("n", "<backspace>n", "\"_dd<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("n", "<backspace><backspace>", "\"_dd<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("v", "n", "d<cmd>AutolistRecalculate<cr>")
            vim.keymap.set("v", "<backspace>", "\"_d<cmd>AutolistRecalculate<cr>")
        end,
    },

I've tested both with keymaps & the actual command (AutolistRecalculate) via the command mode :.

CabalCrow avatar Nov 12 '23 09:11 CabalCrow