From 65ee034c35d9ed70e6347eb6828758fcaebb8b70 Mon Sep 17 00:00:00 2001 From: James Trew <66286082+jamestrew@users.noreply.github.com> Date: Wed, 3 Jan 2024 22:18:39 -0500 Subject: [PATCH] fix(builtin.buffers): better buffer in cwd check (#2847) Previously, using `string.find`, certain characters were taken as regex special characters leading to bad matches. New approach takes bufname truncated to the length of cwd and compares the two strings. (cherry picked from commit 8b56e9bb2d0b8750c2f8cd4efe9738e3c066889b) --- lua/telescope/builtin/__internal.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/telescope/builtin/__internal.lua b/lua/telescope/builtin/__internal.lua index 6cf67b3343..b0fea1743b 100644 --- a/lua/telescope/builtin/__internal.lua +++ b/lua/telescope/builtin/__internal.lua @@ -868,7 +868,8 @@ internal.buffers = function(opts) if cwd:sub(-1) ~= Path.path.sep then cwd = cwd .. Path.path.sep end - return vim.api.nvim_buf_get_name(bufnr):find(cwd) == nil + local bufname_prefix = vim.api.nvim_buf_get_name(bufnr):sub(1, #cwd) + return bufname_prefix ~= cwd end local bufnrs = vim.tbl_filter(function(bufnr)