telescope-repo.nvim icon indicating copy to clipboard operation
telescope-repo.nvim copied to clipboard

Start results cursor at the top instead of the bottom?

Open sgoudham opened this issue 1 year ago ā€¢ 16 comments

This is more of a question than an actual issue with the code, hope that this is okay.

Currently, when invoking :Telescope repo list from the command line, you output similar to this:

Current image

I couldn't help but notice that the cursor/highlighted element is near the bottom. Personally, I'd like it to be just under the search bar. An example of this is the find_files picker within Telescope itself as shown below:

find_files picker image

I had a look through the documentation but I sadly couldn't find anyway to configure this. Is this behaviour configurable in any way?

sgoudham avatar Aug 04 '22 00:08 sgoudham

Hi, thanks for opening this issue. I think there is a telescope setting for that, Iā€™ll look into it later today.

cljoly avatar Aug 07 '22 13:08 cljoly

The following should work @sgoudham :

:Telescope repo list layout_strategy=center

image

This is covered in more details in this part of Telescopeā€™s documentation: :h telescope.layout.vertical().

Please let me know if that does not enable you to do what you want.

cljoly avatar Aug 07 '22 16:08 cljoly

Hi, no sorry, that isn't what I was thinking. In the original issue, you can see that the find_files picker shows results right underneath the search bar.

find_files picker image

whereas, telescope repo is configured like the following:

Telescope repo list image

Is there anyway to configure Telescope repo list to act the same as the find files picker? @cljoly

sgoudham avatar Aug 07 '22 17:08 sgoudham

Ah, ok, so you would want to apply this setting only to the second prompt? Or to both prompt?

The latter should be easier to implement. @sgoudham

cljoly avatar Aug 07 '22 19:08 cljoly

Apologies, I think I've explained this poorly @cljoly

I was just wondering if the telescope-repo picker could be configured to show the search results right underneath the search bar as this is the default behaviour for the base telescope pickers. (e.g. find_files)

The first screenshot I posted in https://github.com/cljoly/telescope-repo.nvim/issues/44#issuecomment-1207449914 is the desired behaviour whereas the second screenshot is the current behaviour of telescope-repo.

sgoudham avatar Aug 07 '22 22:08 sgoudham

@sgoudham no worries. So if I get it right, you would like to see the default behavior for Telescope find_files to be preserved, right?

Iā€™m not sure what causes it not to be preserved, Iā€™ve checked quickly in the code of telescope-repo, I donā€™t think we try to set the layout.

#45 might help with your use case, as you will be able to set the same layout for both prompt (if I got you correctly, you would prefer if you did not have to set any parameter and if the default behavior of find_files was just picked up, but IĀ donā€™t know how to do that yet).

cljoly avatar Aug 07 '22 22:08 cljoly

To clarify further, I mean the way the search results appear. The overall layout of the picker is fine (e.g center) @cljoly

Invoking the command Telescope repo list layout_strategy=center does not change how the search results are ordered, so I'm unsure if changes in #45 will make any difference.

sgoudham avatar Aug 07 '22 22:08 sgoudham

Oh right, your issue is with the ordering of the result and the fact that it ā€œfocusesā€ with the very bottom of the screen when you would want the top result to be focused.

cljoly avatar Aug 07 '22 22:08 cljoly

Invoking the command Telescope repo list layout_strategy=center does not change how the search results are ordered, so I'm unsure if changes in #45 will make any difference.

Yeah, it wonā€™t help. #45 is still probably a more correct behavior (the second prompt will be configurable, which it is not currently).

But yeah, I donā€™t know how to fix your issue.

cljoly avatar Aug 07 '22 22:08 cljoly

Yes! sorry it took so long to clarify that. It feels like doing a google search and having to look at the bottom of the screen instead of looking at the top...

sgoudham avatar Aug 07 '22 22:08 sgoudham

It looks like telescope-repo is the odd one out with the way the search results are populated, so it may be worth looking at telescope-project or even any of the default pickers? Could it be the way you're populating the search results in the code?

sgoudham avatar Aug 07 '22 22:08 sgoudham

Yes! sorry it took so long to clarify that

Thatā€™s alright, perhaps I was slow to understand on that one.

It feels like doing a google search and having to look at the bottom of the screen instead of looking at the top...

Totally

cljoly avatar Aug 07 '22 22:08 cljoly

It looks like telescope-repo is the odd one out with the way the search results are populated, so it may be worth looking at telescope-project or even any of the default pickers? Could it be the way you're populating the search results in the code?

Well, the funny thing is: for me, find_files starts from the bottom too: image

cljoly avatar Aug 07 '22 22:08 cljoly

so it may be worth looking at telescope-project or even any of the default pickers?

Yes. Thatā€™s also why Iā€™m trying to get my find_files to behave like yours.

Could it be the way you're populating the search results in the code?

Well, on the second prompt, Iā€™m not populating anything, I just call the picker with a few options that shouldā„¢ļø be unrelated, like the current file. But maybe they are not šŸ¤·šŸ¼ .

cljoly avatar Aug 07 '22 22:08 cljoly

Iā€™ll try to look more into this issue next weekend, but honestly, I donā€™t know when or even if Iā€™ll have a fix.

In the meantime, could you please paste the part of your config pertaining to Telescope?

cljoly avatar Aug 07 '22 23:08 cljoly

I guess this is more preference than anything, to me it just makes logical sense since your eyes naturally stay around the search bar.

Here's my full config at the minute @cljoly

require("telescope").setup {
    pickers = {
        find_files = {
            hidden = true,
            theme = 'dropdown'
        },
        live_grep = {
            theme = 'dropdown'
        },
        lsp_references = {
            theme = 'dropdown'
        },
        diagnostics = {
            theme = 'dropdown'
        },
        current_buffer_fuzzy_find = {
            theme = 'dropdown'
        }
    },
    defaults = {
        layout_strategy = 'center',
        layout_config = {
            center = {
                anchor = 'S'
            }
        },
        file_ignore_patterns = {
            ".git/"
        },
        mappings = {
            n = {
                ["<A-j>"] = require("telescope.actions").preview_scrolling_down,
                ["<A-k>"] = require("telescope.actions").preview_scrolling_up
            }
        }
    },
    extensions = {
        ['ui-select'] = {
            require("telescope.themes").get_dropdown()
        },
        repo = {
            theme = "dropdown",
            list = {
                search_dirs = {
                    "~/personal/",
                    "~/.config/",
                    [[~/.local/share/nvim/]]
                }
            }
        },
        project = {
            theme = 'dropdown'
        },
        file_browser = {
            theme = "ivy",
            hijack_netrw = true
        }
    }
}

sgoudham avatar Aug 07 '22 23:08 sgoudham

I second this, I was able to move the prompt to the top via layout_config = { prompt_position = "top" } but couldn't find a setting to make the result top-bottom instead of bottom-top. I keep hitting ctrl+j instead of ctrl+k while trying to cycle through the results (maybe muscle memory coming from LeaderF but it still is more "natural" to me)

sirfz avatar Dec 01 '22 20:12 sirfz

Actually, I took another look and I used the config you shared @sgoudham.

For me, this:

Telescope repo list theme=dropdown

gives the expected result, pretty much regardless of the rest of the config. image

And so for you @sirfz, looking into telescope source code, I would guess that you need to use:

Telescope repo list sorting_strategy=ascending

as the sorting strategy appears to be the relevant bit of the them. Please let me know if that works for you.

I'll look for a way to make this configurable in the call to telescope.setup{ā€¦}.

cljoly avatar Dec 01 '22 22:12 cljoly

Ok, so there is currently no way to statically configure this in the call to telescope.setup{ā€¦}.

I could make

        repo = {
            theme = "dropdown",
            list = {
                search_dirs = {
                    "~/personal/",
                    "~/.config/",
                    [[~/.local/share/nvim/]]
                }
            }
        },

work. However I'm a bit concerned with compatibility with the rest of the telescope ecosystem (we might have key collisions and we do launch two selectors, one with the repositories and then the file selector in that repository).

cljoly avatar Dec 01 '22 22:12 cljoly

Hi @cljoly thanks for taking the time to respond! This is actually a general Telescope problem and not related to telescope-repo (I just noticed I posted here, probably after lots of googling and frustration). I'll try to check if there's already an issue about it there

sirfz avatar Dec 02 '22 13:12 sirfz

Found what I wanted here:

in case it helps anyone:

local telescope = require('telescope')

telescope.setup {
  defaults = {
    sorting_strategy = "ascending",  -- display results top->bottom
    layout_config = {
      prompt_position = "top"  -- search bar at the top
    }
  }
}

sirfz avatar Dec 02 '22 14:12 sirfz

@sirfz no worries. Thanks for finding this general setting, it's probably the best course of action here.

@sgoudham I'll close this issue, feel free to reopen it or comment if your problem is not fully solved.

cljoly avatar Dec 02 '22 19:12 cljoly