Skip to content

Commit

Permalink
Add builtin condition for search active
Browse files Browse the repository at this point in the history
  • Loading branch information
konapun committed Jul 23, 2021
1 parent 37943c7 commit d540b45
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ condition.buffer_not_empty -- if buffer not empty return true else false
condition.hide_in_width -- if winwidth(0)/ 2 > 40 true else false
-- find git root, you can use this to check if the project is a git workspace
condition.check_git_workspace()
condition.check_active_search -- if highlight search and search results exist true else false

-- built-in theme
local colors = require('galaxyline.theme').default
Expand Down
8 changes: 8 additions & 0 deletions lua/galaxyline/condition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ function M.check_active_lsp()
return true
end

function M.check_active_search()
local search_count = vim.fn.searchcount({recompute = 1, maxcount = -1})
if vim.v.hlsearch == 1 and search_count.total > 0 then
return true
end
return false
end

return M
4 changes: 2 additions & 2 deletions lua/galaxyline/provider_search.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
local condition = require('galaxyline.condition')
local vim = vim
local M = {}

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

if active then
if condition.check_active_search() then
return '/' .. search_term .. '[' .. search_count.current .. '/' .. search_count.total .. ']'
end
end
Expand Down

0 comments on commit d540b45

Please sign in to comment.