aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2020-07-13 20:58:46 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2020-07-13 20:58:46 -0400
commitb821d05d828aec6ac6c070f00c9115f27f62f9c0 (patch)
treeee4c31e2f1e6dfbd460852a9dffed65dd0ae90c7
parentd89fc360bc24bf98f6c16d3e29e32d9c93e83972 (diff)
downloadtextadept-b821d05d828aec6ac6c070f00c9115f27f62f9c0.tar.gz
textadept-b821d05d828aec6ac6c070f00c9115f27f62f9c0.zip
Limit word highlighting to single words.
-rw-r--r--core/ui.lua3
-rw-r--r--test/test.lua5
2 files changed, 7 insertions, 1 deletions
diff --git a/core/ui.lua b/core/ui.lua
index 5ee4fbd1..e7e608de 100644
--- a/core/ui.lua
+++ b/core/ui.lua
@@ -304,7 +304,8 @@ end, 1)
events_connect(events.UPDATE_UI, function(updated)
if updated and updated & buffer.UPDATE_SELECTION > 0 and
ui.highlight_words and not buffer.selection_empty and
- buffer:is_range_word(buffer.selection_start, buffer.selection_end) then
+ buffer:is_range_word(buffer.selection_start, buffer.selection_end) and
+ buffer:get_sel_text():find('^%S+$') then
clear_highlighted_words()
local word = buffer:text_range(buffer.selection_start, buffer.selection_end)
buffer.search_flags = buffer.FIND_MATCHCASE | buffer.FIND_WHOLEWORD
diff --git a/test/test.lua b/test/test.lua
index 1ae3be7c..155a4a1e 100644
--- a/test/test.lua
+++ b/test/test.lua
@@ -1790,6 +1790,11 @@ function test_ui_highlight_word()
buffer:set_sel(1, 3)
pos = buffer:indicator_end(ui.INDIC_HIGHLIGHT, 2)
assert_equal(pos, 1) -- no highlights
+ -- Verify multi-word selections do not highlight words.
+ buffer:set_sel(buffer:position_from_line(LINE(3)), buffer.line_end_position[LINE(3)])
+ assert(buffer:is_range_word(buffer.selection_start, buffer.selection_end))
+ pos = buffer:indicator_end(ui.INDIC_HIGHLIGHT, 2)
+ assert_equal(pos, 1) -- no highlights
buffer:close(true)
end