From 24cba05bfd60e183f804a81cf0d34795adfe2ed0 Mon Sep 17 00:00:00 2001 From: Chloe Kudryavtsev Date: Fri, 16 Jul 2021 16:58:52 -0400 Subject: micro: textcount: also handle selections we add a space in between the selections to work with the word filter technically, not very nice, but hey maybe pattern could run on every selection separately later and then add up the results that could be good --- dot_config/micro/plug/textcount/textcount.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dot_config/micro/plug/textcount/textcount.lua b/dot_config/micro/plug/textcount/textcount.lua index cd12e58..383892a 100644 --- a/dot_config/micro/plug/textcount/textcount.lua +++ b/dot_config/micro/plug/textcount/textcount.lua @@ -17,9 +17,21 @@ function init() config.MakeCommand('wc', wc, config.NoComplete) end +local function selections(b) + local str = '' + for _, c in b:GetCursors()() do + if c:HasSelection() then + str = str .. ' ' .. util.String(c:GetSelection()) + end + end + return str +end + -- utils local function pattern(b, pat) - local str = util.String(b:Bytes()) + -- if there is a selection, we use it, else we use b:Bytes() + local str = selections(b) + if str == '' then str = util.String(b:Bytes()) end local _, n = str:gsub(pat, '') return n end -- cgit v1.2.3