autolist.nvim
autolist.nvim copied to clipboard
`TAB` has some bug at Insert mode
before tab
after tab
my config
return {
"gaoDean/autolist.nvim",
priority = 1,
ft = {
"markdown",
"text",
},
config = function()
require("autolist").setup()
vim.keymap.set("i", "<tab>", "<cmd>AutolistTab<cr>")
vim.keymap.set("i", "<s-tab>", "<cmd>AutolistShiftTab<cr>")
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>")
vim.keymap.set("n", "<C-r>", "<cmd>AutolistRecalculate<cr>")
end,
dependencies = {
{
"windwp/nvim-autopairs",
event = "VeryLazy",
},
},
}
Hi, could you try this branch? It has a potential fix: https://github.com/gaoDean/autolist.nvim/pull/80
I tried , but it doesn't work properly.
I confirm this behaviour with tab. This is the case even on a fresh config with only lazy.nvim and autolist.nvim installed (and , and on a pure markdown file with only text.
My the test init.lua I used is bootstrapping lazy.nvim, then
require("lazy").setup({
{
"gaoDean/autolist.nvim",
ft = {
"markdown",
"text",
},
config = function()
require("autolist").setup()
vim.keymap.set("i", "<tab>", "<cmd>AutolistTab<cr>")
vim.keymap.set("i", "<s-tab>", "<cmd>AutolistShiftTab<cr>")
end,
},
})
This produces the behaviour that @wqk151 observed.
The problem seems to stem from line 25 in auto.lua:
vim.cmd.normal({ "a" .. parsed_key, bang = true })
Because we append (the 'a' in the command above), the cursor will reenter insert mode one character forward. For example, if we use the text from the original image, we start like
|print(request.args.get("name"))
where '|' is the cursor in insert mode. When we press tab, the above lua code runs. This enters normal mode, then simulates pressing 'a' which enters insert after the current character (append), then issues the tab key press. This means we then have
p| rint(request.args.get("name"))
This goes away if we change 'a' to 'i', but I don't know yet what other functionality this breaks because I don't know this code base. I'm looking at fixing this right now because this bug is irksome.
Reading the branch of that function intended for insert mode (the function is only called once right now, so it is only ever used in insert mode), it appears like the intention is to simply fall back to whatever key the user pressed. For example, if we are not currently in a list, the else in handle_indent runs and either a <tab> or <s-tab> keypress is simulated for the user, and we want to simply fall back to that keypress via the press function. To do this, we can skip the normal command from line 25 and simply use feedkeys:
local function press(key, mode)
if not key or key == "" then return end
local parsed_key = vim.api.nvim_replace_termcodes(key, true, false, true)
if mode == "i" then
vim.api.nvim_feedkeys(parsed_key, 'n', true)
else
vim.cmd.normal({ parsed_key, bang = true })
end
end
Using this version of the function, this is the functionality I have with tab and shift-tab:
- Tab and shift-tab indent and dedent when at the end of the line (the intended functionality of autolist)
- tab works correctly in other contexts, such as at the start of the line
Disclaimer: I don't have anything mapped to shift-tab normally, so I can't show it working outside of the list context.