aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2015-07-25 10:25:26 -0400
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2015-07-25 10:25:26 -0400
commit473382638da565c890fcf8e6119f95dbdf918973 (patch)
treea0c996ece7bc479dc5743d8ed27fdb96ac101c32
parentc883f5126cbcd2322a6deda024f8c99ed20e8a86 (diff)
Highlight found text in find in files results.
-rw-r--r--core/ui.lua3
-rw-r--r--modules/textadept/find.lua27
-rw-r--r--properties.lua2
-rw-r--r--themes/dark.lua4
-rw-r--r--themes/light.lua2
-rw-r--r--themes/term.lua1
6 files changed, 31 insertions, 8 deletions
diff --git a/core/ui.lua b/core/ui.lua
index dbcb8f29..3b787e8f 100644
--- a/core/ui.lua
+++ b/core/ui.lua
@@ -28,6 +28,9 @@ local ui = ui
-- The default value is `true`.
-- @field SILENT_PRINT (bool)
-- Whether or not to print messages to buffers silently.
+-- This is not guaranteed to be a constant value, as Textadept may change it
+-- for the editor's own purposes. This flag should be used only in conjunction
+-- with a group of [`ui.print()`]() and [`ui._print()`]() function calls.
-- The default value is `false`, and focuses buffers when messages are printed
-- to them.
module('ui')]]
diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua
index 4c369f20..a6e7d61f 100644
--- a/modules/textadept/find.lua
+++ b/modules/textadept/find.lua
@@ -52,6 +52,8 @@ local M = ui.find
-- @field in_files_label_text (string, Write-only)
-- The text of the "In files" label.
-- This is primarily used for localization.
+-- @field INDIC_FIND (number)
+-- The find in files highlight indicator number.
-- @field _G.events.FIND_WRAPPED (string)
-- Emitted when a text search wraps (passes through the beginning of the
-- buffer), either from bottom to top (when searching for a next occurrence),
@@ -73,6 +75,8 @@ M.lua_pattern_label_text = not CURSES and _L['_Lua pattern'] or
_L['Pattern(F3)']
M.in_files_label_text = not CURSES and _L['_In files'] or _L['Files(F4)']
+M.INDIC_FIND = _SCINTILLA.next_indic_number()
+
-- Events.
events.FIND_WRAPPED = 'find_wrapped'
@@ -243,22 +247,31 @@ function M.find_in_files(dir)
if not M.lua then text = text:gsub('([().*+?^$%%[%]-])', '%%%1') end
if not M.match_case then text = text:lower() end
if M.whole_word then text = '%f[%w_]'..text..'%f[^%w_]' end -- TODO: wordchars
- local matches = {_L['Find:']..' '..text}
+
+ if buffer._type ~= _L['[Files Found Buffer]'] then preferred_view = view end
+ ui.SILENT_PRINT = false
+ ui._print(_L['[Files Found Buffer]'], _L['Find:']..' '..text)
+ buffer.indicator_current = M.INDIC_FIND
+
+ local found = false
lfs.dir_foreach(dir, function(file)
local match_case = M.match_case
local line_num = 1
for line in io.lines(file) do
- if (match_case and line or line:lower()):find(text) then
+ local s, e = (match_case and line or line:lower()):find(text)
+ if s and e then
file = file:iconv('UTF-8', _CHARSET)
- matches[#matches + 1] = ('%s:%s:%s'):format(file, line_num, line)
+ buffer:append_text(('%s:%d:%s\n'):format(file, line_num, line))
+ local pos = buffer:position_from_line(buffer.line_count - 2) +
+ #file + #tostring(line_num) + 2
+ buffer:indicator_fill_range(pos + s - 1, e - s + 1)
+ found = true
end
line_num = line_num + 1
end
end, M.FILTER, true)
- if #matches == 1 then matches[2] = _L['No results found'] end
- matches[#matches + 1] = ''
- if buffer._type ~= _L['[Files Found Buffer]'] then preferred_view = view end
- ui._print(_L['[Files Found Buffer]'], table.concat(matches, '\n'))
+ if not found then buffer:append_text(_L['No results found']) end
+ ui._print(_L['[Files Found Buffer]'], '') -- goto end, set save pos, etc.
end
-- Replaces found text.
diff --git a/properties.lua b/properties.lua
index 9133e24a..c534b57b 100644
--- a/properties.lua
+++ b/properties.lua
@@ -123,6 +123,8 @@ buffer:marker_define(buffer.MARKNUM_FOLDERMIDTAIL, buffer.MARK_TCORNER)
--buffer:marker_enable_highlight(true)
-- Indicators.
+buffer.indic_style[ui.find.INDIC_FIND] = buffer.INDIC_ROUNDBOX
+if not CURSES then buffer.indic_under[ui.find.INDIC_FIND] = true end
local INDIC_BRACEMATCH = textadept.editing.INDIC_BRACEMATCH
buffer.indic_style[INDIC_BRACEMATCH] = buffer.INDIC_BOX
buffer:brace_highlight_indicator(not CURSES, INDIC_BRACEMATCH)
diff --git a/themes/dark.lua b/themes/dark.lua
index 3de9e2d6..84c25c64 100644
--- a/themes/dark.lua
+++ b/themes/dark.lua
@@ -20,7 +20,7 @@ property['color.dark_white'] = 0xCCCCCC
-- Dark colors.
--property['color.dark_red'] = 0x1A1A66
---property['color.dark_yellow'] = 0x1A6666
+property['color.dark_yellow'] = 0x1A6666
--property['color.dark_green'] = 0x1A661A
--property['color.dark_teal'] = 0x66661A
--property['color.dark_purple'] = 0x661A66
@@ -119,6 +119,8 @@ for i = 25, 31 do -- fold margin markers
end
-- Indicators.
+buffer.indic_fore[ui.find.INDIC_FIND] = property_int['color.dark_yellow']
+buffer.indic_alpha[ui.find.INDIC_FIND] = 255
local INDIC_BRACEMATCH = textadept.editing.INDIC_BRACEMATCH
buffer.indic_fore[INDIC_BRACEMATCH] = property_int['color.light_grey']
local INDIC_HIGHLIGHT = textadept.editing.INDIC_HIGHLIGHT
diff --git a/themes/light.lua b/themes/light.lua
index 18f19e3f..ac45310c 100644
--- a/themes/light.lua
+++ b/themes/light.lua
@@ -119,6 +119,8 @@ for i = 25, 31 do -- fold margin markers
end
-- Indicators.
+buffer.indic_fore[ui.find.INDIC_FIND] = property_int['color.yellow']
+buffer.indic_alpha[ui.find.INDIC_FIND] = 255
local INDIC_BRACEMATCH = textadept.editing.INDIC_BRACEMATCH
buffer.indic_fore[INDIC_BRACEMATCH] = property_int['color.grey']
local INDIC_HIGHLIGHT = textadept.editing.INDIC_HIGHLIGHT
diff --git a/themes/term.lua b/themes/term.lua
index c3701e9b..b99e870b 100644
--- a/themes/term.lua
+++ b/themes/term.lua
@@ -76,6 +76,7 @@ buffer.marker_back[textadept.run.MARK_WARNING] = property_int['color.yellow']
buffer.marker_back[textadept.run.MARK_ERROR] = property_int['color.red']
-- Indicators.
+buffer.indic_fore[ui.find.INDIC_FIND] = property_int['color.yellow']
local INDIC_HIGHLIGHT = textadept.editing.INDIC_HIGHLIGHT
buffer.indic_fore[INDIC_HIGHLIGHT] = property_int['color.yellow']