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

Odd default behavior with flex layout when resizing horizontally #3138

Closed
ronandalton opened this issue May 26, 2024 · 1 comment · Fixed by #3148
Closed

Odd default behavior with flex layout when resizing horizontally #3138

ronandalton opened this issue May 26, 2024 · 1 comment · Fixed by #3148
Labels
bug Something isn't working reproducible Bug that can be reproduced.

Comments

@ronandalton
Copy link
Contributor

ronandalton commented May 26, 2024

Description

When using the flex layout with default settings, odd behavior is observed when resizing the window horizontally. The preview pane is hidden at certain widths.

Neovim version

NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713484068

Operating system and version

Linux 6.8.1

Telescope version / branch / rev

master (c2ce039)

checkhealth telescope

Checking for required plugins ~
- OK plenary installed.
- WARNING nvim-treesitter not found. (Required for `:Telescope treesitter`.)

Checking external dependencies ~
- OK rg: found ripgrep 14.1.0
- OK fd: found fd 9.0.0

===== Installed extensions ===== ~

Telescope Extension: `fzf` ~
- OK lib working as expected
- OK file_sorter correctly configured
- OK generic_sorter correctly configured

Steps to reproduce

  1. nvim -nu minimal.lua
  2. Resize Neovim window so it's at least 130x50 characters
  3. Execute :Telescope live_grep
  4. Start reducing the width of the window gradually

Expected behavior

The preview pane should remain visible while resizing horizontally. The layout should flip to vertical once the width is reduced below 120.

Actual behavior

There is a period while resizing horizontally where the preview pane is not visible. This happens between widths of 120 and 100. When the window width is reduced below 100, the preview appears again in a vertical layout. This doesn't make sense because if you started with a vertical layout, you wouldn't expect increasing the width of the window to show less of the UI.

Video:
https://github.com/nvim-telescope/telescope.nvim/assets/86718942/f8e272a0-b719-4752-9adc-fa08f085c099

Analysis

The reason this happens is because of a mismatch between the default flip_columns and flip_lines values (which are 100 and 20) for the flex layout and the preview_cutoff values for the horizontal and vertical layouts (which are 120 and 40). When the window width is increased to 100, the horizontal layout is switched to, but the horizontal layout won't display a preview pane because the window width is below the preview cutoff for the horizontal layout.

My suggested change would be to set the default flip_columns and flip_lines values in the flex layout code to 120 and 40 respectively. This would ensure the vertical layout is only switched away from when the window is wide enough for the horizontal layout to display correctly. Alternatively, the default clip_columns and flip_lines values could be taken from the preview_cutoff values for the horizontal and vertical layouts automatically.

Note that the desired behavior can be achieved just by adding the following code to telescope's config, but as I consider the default behavior a bit strange, I thought it might be better to have that changed so this config isn't needed.

        defaults = {
          layout_strategy = 'flex',
          layout_config = {
            flex = {
              flip_columns = 120,
              flip_lines = 40,
            },
          },
        },

Minimal config

vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvim/site]])
local package_root = "/tmp/nvim/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
	require("packer").startup({
		{
			"wbthomason/packer.nvim",
			{
				"nvim-telescope/telescope.nvim",
				requires = {
					"nvim-lua/plenary.nvim",
					{ "nvim-telescope/telescope-fzf-native.nvim", run = "make" },
				},
			},
		},
		config = {
			package_root = package_root,
			compile_path = install_path .. "/plugin/packer_compiled.lua",
			display = { non_interactive = true },
		},
	})
end
_G.load_config = function()
	require("telescope").setup({ defaults = { layout_strategy = "flex" } })
	require("telescope").load_extension("fzf")
end
if vim.fn.isdirectory(install_path) == 0 then
	print("Installing Telescope and dependencies.")
	vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]])
@ronandalton ronandalton added the bug Something isn't working label May 26, 2024
@jamestrew jamestrew added the reproducible Bug that can be reproduced. label May 26, 2024
@ronandalton
Copy link
Contributor Author

I created a PR that fixes this issue. I went with my alternate suggestion of setting the default clip_columns and flip_lines values to the preview_cutoff values for the vertical and horizontal layouts. This should be more robust since if those values change, these values won't get out of sync again. It also means less configuration is needed if a user changes their default preview_cutoff values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproducible Bug that can be reproduced.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants