From 8b56e9bb2d0b8750c2f8cd4efe9738e3c066889b 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. --- 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 9926c36871..84c65b0872 100644 --- a/lua/telescope/builtin/__internal.lua +++ b/lua/telescope/builtin/__internal.lua @@ -886,7 +886,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)