diff options
author | 2009-02-05 17:21:52 -0500 | |
---|---|---|
committer | 2009-02-05 17:21:52 -0500 | |
commit | 25b785dfc7f125b66a6ed1fc7b661a2435dc7bf0 (patch) | |
tree | 97bc846795271bffdecf9acca3ca14d2a9fb0a3c /core/ext | |
parent | 31b6f1d5a76c9a37da074011866fc6d68b0413d6 (diff) | |
download | textadept-25b785dfc7f125b66a6ed1fc7b661a2435dc7bf0.tar.gz textadept-25b785dfc7f125b66a6ed1fc7b661a2435dc7bf0.zip |
Fixed a bug and added enhancements to Find in Files.
Double-clicking a search result will open the file in the previous view (if it
exists) rather than clobbering the current one. Also added the find text to the
output.
Diffstat (limited to 'core/ext')
-rw-r--r-- | core/ext/find.lua | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/core/ext/find.lua b/core/ext/find.lua index 4938f3af..2608e862 100644 --- a/core/ext/find.lua +++ b/core/ext/find.lua @@ -4,6 +4,7 @@ local textadept = _G.textadept local find = textadept.find local MARK_REPLACEALL_END = 0 +local previous_view --- -- [Local table] Text escape sequences with their associated characters. @@ -91,7 +92,7 @@ function find.find(text, next, flags, nowrap, wrapped) local match_case = find.match_case local whole_word = find.whole_word local format = string.format - local matches = {} + local matches = { 'Find: '..text } function search_file(file) local line_num = 1 for line in io.lines(file) do @@ -118,7 +119,9 @@ function find.find(text, next, flags, nowrap, wrapped) end end search_dir(dir) - if #matches == 0 then matches[1] = locale.FIND_NO_RESULTS end + if #matches == 1 then matches[2] = locale.FIND_NO_RESULTS end + matches[#matches + 1] = '' + previous_view = view textadept._print('shows_files_found', table.concat(matches, '\n')) end return @@ -252,9 +255,12 @@ function goto_file(pos, line_num) if buffer.shows_files_found then line = buffer:get_line(line_num) local file, line_num = line:match('^(.+):(%d+):.+$') - textadept.io.open(file) - buffer:ensure_visible_enforce_policy(line_num - 1) - buffer:goto_line(line_num - 1) + if file and line_num then + if previous_view then previous_view:focus() end + textadept.io.open(file) + buffer:ensure_visible_enforce_policy(line_num - 1) + buffer:goto_line(line_num - 1) + end end end textadept.events.add_handler('double_click', goto_file) |