1
1
local M = {}
2
2
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
+
3
10
M .construct_query_path = function (args )
4
11
local ext = vim .fn .expand (" %:e" )
5
12
27
34
M .construct_query_text = function ()
28
35
local utils = require (" csgithub.utils" )
29
36
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 ())
33
41
else
34
42
-- normal mode
35
43
text = vim .fn .expand (" <cword>" )
36
44
end
37
-
38
45
return text
39
46
end
40
47
43
50
M .construct_query = function (args )
44
51
local query_parts = {}
45
52
53
+ local query_text = M .construct_query_text ()
54
+ if query_text == " " then
55
+ return nil
56
+ end
46
57
-- path:
47
58
if args .includeFilename or args .includeExtension then
48
59
local path = M .construct_query_path (args )
@@ -51,7 +62,7 @@ M.construct_query = function(args)
51
62
end
52
63
53
64
-- text
54
- table.insert (query_parts , M . construct_query_text () )
65
+ table.insert (query_parts , query_text )
55
66
56
67
return table.concat (query_parts , " " )
57
68
end
0 commit comments