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

feature: Responsive Telescope layouts #2173

Open
1 task done
JonatasAmaral opened this issue Dec 11, 2023 · 3 comments
Open
1 task done

feature: Responsive Telescope layouts #2173

JonatasAmaral opened this issue Dec 11, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@JonatasAmaral
Copy link

JonatasAmaral commented Dec 11, 2023

Did you check the docs?

  • I have read all the LazyVim docs

Is your feature request related to a problem? Please describe.

When using LazyVim in a vertical screen, :Telescope live_grep (<leader>/), that has horizontal layout, gets without the preview

Describe the solution you'd like

It would be nice if LazyVim could check if has move height than width, and if so, exec :Telescope ... layout_strategy=vertical for <leader>/|<leader>sg|all Ts commands with preview

{ "<leader>/", Util.telescope("live_grep"), desc = "Find in Files (Grep)" },

Describe alternatives you've considered

I've created a plugins/telescope.lua to overwrite some keys, but that' too much to overwrite i suppose.
Also, it may be a beneficial thing for every one.

Additional context

Here's how i've done on my side

-- gives "esponsiveness" to Telescope's commands with previews
-- by open in vertical layout for vertical screens

local function isVertical()
  local width = vim.api.nvim_get_option("columns")
  local height = vim.api.nvim_get_option("lines")

  print("echo 'screen is " .. width .. "x" .. height .. "'")

  return height > width / 2 -- lines are wider than columns in px
end

local function responsiveGrep()
  local direction = isVertical() and "vertical" or "horizontal"
  require("telescope.builtin").live_grep({ layout_strategy = direction })
end
local function responsiveFindFiles()
  local direction = isVertical() and "vertical" or "horizontal"
  require("telescope.builtin").files({ layout_strategy = direction })
end

return {
  "nvim-telescope/telescope.nvim",
  keys = {
    -- { "<leader>/", vim.NIL },
    { "<leader>/", responsiveGrep, desc = "Find in Files (Grep)" },
    { "<leader>sg", responsiveGrep, desc = "Grep (root dir)" },
    { "<leader><space>", responsiveFindFiles, desc = "Find Files (root dir)" },
    { "<leader>ff", responsiveFindFiles, desc = "Find Files (root dir)" },
  },
}

No response

@JonatasAmaral JonatasAmaral added the enhancement New feature or request label Dec 11, 2023
@dpetka2001
Copy link
Contributor

dpetka2001 commented Dec 11, 2023

You should look into :h telescope.layout.flex. No need to change this for every keymap (since flex will be used for every picker if you define it as the default layout_strategy) or use custom functions to recognize if it should be horizontal or vertical. Really not LazyVim related, since it's builtin in Telescope.

Edit: you can also look into :h telescope.layout.horizontal and specifically experiment with the preview_cutoff value. But, you will get with a narrower horizontal layout with this and would suggest to use flex instead.

@JonatasAmaral
Copy link
Author

Sorry the delay

I experimented with flex, it's cool how it swaps on resize/scale.
It gets almost there, but i doesn't feel "flexible" enough

You set the flip_columns and flip_lines to swap it from vert to horizontal.
With that fixed value for example:

  • my laptop's screen get horizontal, makes sense
  • but my side (vert) monitor does too
  • i fine tune the number, but then if i split my vert screen, it keep a vertical layout
  • fine tune the flip_lines, then don't match my main screen on split
    ...

I really expect layout strategy to depend on aspect-ratio instead on size
oppose to... well, size, either of the panel, preview of cutoff

So, flex would be perfect if flip_* could receive a function that evaluates it's value
gonna open a request there

But for now, the way above feels to me a better "generalist" option.
Maybe i'll give a try to make my own strategy.

And finally, i do think that setting better defaults is indeed LazyVim related.
So for myself, it's kind of solved with the (non optimal) config above, but that's a opportunity for a small improvement of the project as a whole, even if only setting "flex" the default strategy

@dpetka2001
Copy link
Contributor

I see what you mean. You have 2 different monitors. I only have one horizontal and couldn't test the different behavior of flex in a vertical monitor. I only experimented with flex in the horizontal monitor and tried to resize my terminal and observed the behavior I mentioned.
On that aspect, yes, it seems that if flip_* values could take a function would make more sense.
As far as the Lazyvim defaults are concerned, I guess in retrospect, I agree with your suggestion above (since I believed that flex would take care of your problem under my false assumptions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants