nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.48k stars 824 forks source link

Keep initial sorting when typing query for oldfiles #3078

Open albean opened 4 months ago

albean commented 4 months ago

Is your feature request related to a problem? Please describe. I use require("telescope.builtin").oldfiles to navigate with the sort_mru option enabled. But as long as I start typing, files are resorted based on match, not by the initial sorting.

I've tried tiebreak workaround form #2539 but it doesnt make difference for my use case. I dont see how it would make it either. The problem seems to be the resorting feature in query logic, which is useful when we don't care about initial sorting, which I don't, except foroldifiles

Describe the solution you'd like I would like to pass some option to disable resorting while typing.

albean commented 4 months ago

I'm not particularly proud about this workaround, but it works perfectly for me:

function M.buffers()
  local builtin = require('telescope.builtin')

  local sorter = require("telescope.sorters").get_fzy_sorter()

  local fn = sorter.scoring_function

  sorter.scoring_function = function(_, prompt, line)
    local score = fn(_, prompt, line)

    return score > 0 and 1 or -1;
  end

  builtin.oldfiles({
    sorter = sorter,
    tiebreak = function(current_entry, existing_entry, _)
      return current_entry.index > existing_entry.index
    end,
  })
end

I'm not closing the issue in case you want to resolve it in more proper way since above solution feels like hacking more then configuring. Its fine by me.

As I said - default behaviour is useful in every case but this.