Skip to content

Commit 2eb504a

Browse files
committed
Add builtin condition for search active
1 parent 37943c7 commit 2eb504a

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ condition.buffer_not_empty -- if buffer not empty return true else false
137137
condition.hide_in_width -- if winwidth(0)/ 2 > 40 true else false
138138
-- find git root, you can use this to check if the project is a git workspace
139139
condition.check_git_workspace()
140+
condition.check_active_search -- if highlight search and search results exist true else false
140141

141142
-- built-in theme
142143
local colors = require('galaxyline.theme').default

lua/galaxyline/condition.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,12 @@ function M.check_active_lsp()
4040
return true
4141
end
4242

43+
function M.check_active_search()
44+
local search_count = vim.fn.searchcount({recompute = 1, maxcount = -1})
45+
if vim.v.hlsearch == 1 and search_count.total > 0 then
46+
return true
47+
end
48+
return false
49+
end
50+
4351
return M

lua/galaxyline/provider_search.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
local condition = require('condition')
12
local vim = vim
23
local M = {}
34

45
function M.get_search_results()
56
local search_term = vim.fn.getreg('/')
67
local search_count = vim.fn.searchcount({recompute = 1, maxcount = -1})
7-
local active = vim.v.hlsearch == 1 and search_count.total > 0
88

9-
if active then
9+
if condition.check_active_search() then
1010
return '/' .. search_term .. '[' .. search_count.current .. '/' .. search_count.total .. ']'
1111
end
1212
end

0 commit comments

Comments
 (0)