From bb58f7b973bc6aabfdaabfd536beb7644a364d34 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Tue, 8 Jun 2021 02:10:14 -0400 Subject: [selectionhighlight] added option to not highlight empty spaces. --- plugins/selectionhighlight.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/selectionhighlight.lua b/plugins/selectionhighlight.lua index fd10239..132e6aa 100644 --- a/plugins/selectionhighlight.lua +++ b/plugins/selectionhighlight.lua @@ -1,9 +1,13 @@ -- mod-version:1 -- lite-xl 1.16 local style = require "core.style" local DocView = require "core.docview" +local config = require "core.config" -- originally written by luveti +-- Set to true to also highlight empty spaces +config.highlight_spaces = false + local function draw_box(x, y, w, h, color) local r = renderer.draw_rect local s = math.ceil(SCALE) @@ -18,13 +22,24 @@ local draw_line_body = DocView.draw_line_body function DocView:draw_line_body(idx, x, y) local line1, col1, line2, col2 = self.doc:get_selection(true) - if line1 == line2 and col1 ~= col2 then + local selection = self.doc:get_text(line1, col1, line2, col2) + if + line1 == line2 and col1 ~= col2 + and + ( + config.highlight_spaces + or + not selection:match("^%s+$") + ) + then local lh = self:get_line_height() local selected_text = self.doc.lines[line1]:sub(col1, col2 - 1) local current_line_text = self.doc.lines[idx] local last_col = 1 while true do - local start_col, end_col = current_line_text:find(selected_text, last_col, true) + local start_col, end_col = current_line_text:find( + selected_text, last_col, true + ) if start_col == nil then break end local x1 = x + self:get_col_x_offset(idx, start_col) local x2 = x + self:get_col_x_offset(idx, end_col + 1) -- cgit v1.2.3 From 69547591d228a00140889df0b7fccda6e597c8d0 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Fri, 11 Jun 2021 17:35:46 -0400 Subject: Removed configuration to enable selecting empty spaces. --- plugins/selectionhighlight.lua | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/plugins/selectionhighlight.lua b/plugins/selectionhighlight.lua index 132e6aa..93ac0fb 100644 --- a/plugins/selectionhighlight.lua +++ b/plugins/selectionhighlight.lua @@ -5,9 +5,6 @@ local config = require "core.config" -- originally written by luveti --- Set to true to also highlight empty spaces -config.highlight_spaces = false - local function draw_box(x, y, w, h, color) local r = renderer.draw_rect local s = math.ceil(SCALE) @@ -23,15 +20,7 @@ local draw_line_body = DocView.draw_line_body function DocView:draw_line_body(idx, x, y) local line1, col1, line2, col2 = self.doc:get_selection(true) local selection = self.doc:get_text(line1, col1, line2, col2) - if - line1 == line2 and col1 ~= col2 - and - ( - config.highlight_spaces - or - not selection:match("^%s+$") - ) - then + if line1 == line2 and col1 ~= col2 and not selection:match("^%s+$") then local lh = self:get_line_height() local selected_text = self.doc.lines[line1]:sub(col1, col2 - 1) local current_line_text = self.doc.lines[idx] -- cgit v1.2.3