Skip to content
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

Folds are stick to the start of the line and follow cursor when moving horizotally #200

Open
ls-devs opened this issue Feb 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ls-devs
Copy link

ls-devs commented Feb 7, 2024

Neovim version (nvim -v | head -n1)

NVIM v0.10.0-dev-2296+gcca8a78ea

Operating system/version

Windows 11 (WSL)

How to reproduce the issue

I don't have any repro.lua but I can show a video of the problem followed by my UFO config.

EDIT : Happens when vim option wrap is set to false

Video :

ufo.mp4

Ufo config :

local handler = function(virtText, lnum, endLnum, width, truncate)
	local newVirtText = {}
	local suffix = (" 󱞤 %d "):format(endLnum - lnum)
	local sufWidth = vim.fn.strdisplaywidth(suffix)
	local targetWidth = width - sufWidth
	local curWidth = 0
	for _, chunk in ipairs(virtText) do
		local chunkText = chunk[1]
		local chunkWidth = vim.fn.strdisplaywidth(chunkText)
		if targetWidth > curWidth + chunkWidth then
			table.insert(newVirtText, chunk)
		else
			chunkText = truncate(chunkText, targetWidth - curWidth)
			local hlGroup = chunk[2]
			table.insert(newVirtText, { chunkText, hlGroup })
			chunkWidth = vim.fn.strdisplaywidth(chunkText)
			-- str width returned from truncate() may less than 2nd argument, need padding
			if curWidth + chunkWidth < targetWidth then
				suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth)
			end
			break
		end
		curWidth = curWidth + chunkWidth
	end
	table.insert(newVirtText, { suffix, "MoreMsg" })
	return newVirtText
end

return {
	"kevinhwang91/nvim-ufo",
	event = "BufReadPost",
	opts = {
		provider_selector = function(bufnr, filetype, buftype)
			return { "treesitter", "indent" }
		end,
		fold_virt_text_handler = handler,
		preview = {
			win_config = {
				winhighlight = "Normal:Folded",
				winblend = 0,
			},
			mappings = {
				scrollU = "<C-u>",
				scrollD = "<C-d>",
				jumpTop = "[",
				jumpBot = "]",
			},
		},
	},
	dependencies = {
		{ "kevinhwang91/promise-async" },
		{
			"luukvbaal/statuscol.nvim",
			opts = {
				foldfunc = "builtin",
				setopt = true,
				relculright = true,
			},
			config = function(_, opts)
				require("statuscol").setup(vim.tbl_deep_extend("force", opts, {
					segments = {
						{ text = { "%s" }, click = "v:lua.ScSa" },
						{ text = { require("statuscol.builtin").lnumfunc, " " }, click = "v:lua.ScLa" },
						{ text = { require("statuscol.builtin").foldfunc, "  " }, click = "v:lua.ScFa" },
					},
				}))
			end,
		},
	},
}

Expected behavior

1 - Fold a function
2 - Move horizontally
3 - Fold is staying at its position

Actual behavior

1 - Fold a function
2 - Move horizontally
3 - Fold is following cursor horizontal moovements

@ls-devs ls-devs added the bug Something isn't working label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant