11local M = {}
22
3+ --- useful for visual line mode when extra whitespace is
4+ --- included in search query
5+ --- @param s string
6+ local function trim_string (s )
7+ return (s :gsub (" ^%s*(.-)%s*$" , " %1" ))
8+ end
9+
310M .construct_query_path = function (args )
411 local ext = vim .fn .expand (" %:e" )
512
2734M .construct_query_text = function ()
2835 local utils = require (" csgithub.utils" )
2936 local text = " "
30- if vim .fn .mode () == " v" then
31- -- visual mode
32- text = utils .get_visual_selection ()
37+ local mode = vim .api .nvim_get_mode ().mode
38+ if mode == " v" or mode == " V" then
39+ -- visual mode, visual line mode
40+ text = trim_string (utils .get_visual_selection ())
3341 else
3442 -- normal mode
3543 text = vim .fn .expand (" <cword>" )
3644 end
37-
3845 return text
3946end
4047
4350M .construct_query = function (args )
4451 local query_parts = {}
4552
53+ local query_text = M .construct_query_text ()
54+ if query_text == " " then
55+ return nil
56+ end
4657 -- path:
4758 if args .includeFilename or args .includeExtension then
4859 local path = M .construct_query_path (args )
@@ -51,7 +62,7 @@ M.construct_query = function(args)
5162 end
5263
5364 -- text
54- table.insert (query_parts , M . construct_query_text () )
65+ table.insert (query_parts , query_text )
5566
5667 return table.concat (query_parts , " " )
5768end
0 commit comments