nvim-telescope / telescope.nvim

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

grep_string visual selection fails in V-BLOCK mode #2497

Open zaixi opened 1 year ago

zaixi commented 1 year ago

Description

Use to enter V-BLOCK mode, use grep_string to search after selecting text, the search result is not the selected text

Neovim version

NVIM v0.8.3                                                                                                                                             
Build type: RelWithDebInfo                                                                                                                              
LuaJIT 2.1.0-beta3                                                                                                                                      
Compilation: /usr/bin/gcc-10 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Og -g -Wall -Wextra
 -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -
Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU
_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/__w/neovim/neovim/build/cmake.config -I/__w/neovim/neovim/src -I/__w/n
eovim/neovim/.deps/usr/include -I/usr/include -I/__w/neovim/neovim/build/src/nvim/auto -I/__w/neovim/neovim/build/include                               
Compiled by root@7fa51f9b5ede                                                                                                                           

Features: +acl +iconv +tui                                                                                                                              
See ":help feature-compile

Operating system and version

Ubuntu 20.04.2 LTS \n \l

Telescope version / branch / rev

master

checkhealth telescope

telescope: require("telescope.health").check()                                                                                                          
========================================================================                                                                                
## Checking for required plugins                                                                                                                        
  - OK: plenary installed.                                                                                                                              
  - OK: nvim-treesitter installed.                                                                                                                      

## Checking external dependencies                                                                                                                       
  - OK: rg: found ripgrep 11.0.2                                                                                                                        
  - OK: fd: found fd 7.4.0                                                                                                                              

## ===== Installed extensions =====                                                                                                                     

## Telescope Extension: `fzf`                                                                                                                           
  - OK: lib working as expected                                                                                                                         
  - OK: file_sorter correctly configured                                                                                                                
  - OK: generic_sorter correctly configured                                                                                                             

## Telescope Extension: `lsp_handlers`                                                                                                                  
  - INFO: No healthcheck provided                                                                                                                       

## Telescope Extension: `terms`
  - INFO: No healthcheck provided                                                                                                                       

## Telescope Extension: `themes`                                                                                                                        
  - INFO: No healthcheck provided

Steps to reproduce

  1. nvim 0.9.0
  2. install telescope master
  3. open file
  4. enter V-BLOCK mode
  5. selecting text
  6. use grep_string search

Expected behavior

No response

Actual behavior

image image

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      {
        'nvim-telescope/telescope.nvim',
        requires = {
          'nvim-lua/plenary.nvim',
          { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' },
        },
      },
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
      display = { non_interactive = true },
    },
  }
end
_G.load_config = function()
  require('telescope').setup()
  require('telescope').load_extension('fzf')
  -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing Telescope and dependencies.")
  vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end
load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
Marskey commented 1 year ago
local function getVisualSelection()
    vim.cmd('noau normal! "vy"')
    local text = vim.fn.getreg("v")
    vim.fn.setreg("v", {})

    text = string.gsub(text, "\n", "")
    if #text > 0 then
        return text
    else
        return ""
    end
end

    v = {
        ["<leader>ff"] = {
            function()
                require("telescope.builtin").find_files({
                    default_text = getVisualSelection(),
                })
            end,
            "find files",
        },
        ["<leader>ft"] = {
            function()
                require("telescope.builtin").live_grep({
                    default_text = getVisualSelection(),
                    only_sort_text = true,
                    additional_args = function()
                        return { "--pcre2" }
                    end,
                })
            end,
            "Find Text",
        },
    },

use default_text