From d540b451e39b2995585d05293c0ba10f6702ef0a Mon Sep 17 00:00:00 2001 From: konapun Date: Thu, 22 Jul 2021 22:39:53 -0500 Subject: [PATCH] Add builtin condition for search active --- README.md | 1 + lua/galaxyline/condition.lua | 8 ++++++++ lua/galaxyline/provider_search.lua | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index af83247..e0c6c48 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/galaxyline/condition.lua b/lua/galaxyline/condition.lua index a0a0628..7df6694 100644 --- a/lua/galaxyline/condition.lua +++ b/lua/galaxyline/condition.lua @@ -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 diff --git a/lua/galaxyline/provider_search.lua b/lua/galaxyline/provider_search.lua index debef61..03d47b7 100644 --- a/lua/galaxyline/provider_search.lua +++ b/lua/galaxyline/provider_search.lua @@ -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