瀏覽代碼

[Feature]: Use Telescope's git_files with fallback (#2089)

Landon Schropp 3 年之前
父節點
當前提交
a3cf3b1f2a
共有 2 個文件被更改,包括 11 次插入1 次删除
  1. 10 0
      lua/lvim/core/telescope/custom-finders.lua
  2. 1 1
      lua/lvim/core/which-key.lua

+ 10 - 0
lua/lvim/core/telescope/custom-finders.lua

@@ -82,4 +82,14 @@ function M.view_lunarvim_changelog()
   }):find()
 end
 
+-- Smartly opens either git_files or find_files, depending on whether the working directory is
+-- contained in a Git repo.
+function M.find_project_files()
+  local ok = pcall(builtin.git_files)
+
+  if not ok then
+    builtin.find_files()
+  end
+end
+
 return M

+ 1 - 1
lua/lvim/core/which-key.lua

@@ -68,7 +68,7 @@ M.config = function()
       ["q"] = { "<cmd>q!<CR>", "Quit" },
       ["/"] = { "<cmd>lua require('Comment').toggle()<CR>", "Comment" },
       ["c"] = { "<cmd>BufferClose!<CR>", "Close Buffer" },
-      ["f"] = { "<cmd>Telescope find_files<CR>", "Find File" },
+      ["f"] = { require("lvim.core.telescope.custom-finders").find_project_files, "Find File" },
       ["h"] = { "<cmd>nohlsearch<CR>", "No Highlight" },
       b = {
         name = "Buffers",