From 53631f9229b235f4fe203845a14d257105e070f6 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+orbitalquark@users.noreply.github.com> Date: Tue, 10 Nov 2020 11:10:12 -0500 Subject: Added argument to `events.FIND_RESULT_FOUND`. This fixes a bug introduced by r3029 when invoking search via a macro. --- docs/api.md | 3 +++ modules/lua/ta_api | 2 +- modules/textadept/find.lua | 9 ++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/api.md b/docs/api.md index f9b8cd77..a0110eb5 100644 --- a/docs/api.md +++ b/docs/api.md @@ -8791,6 +8791,9 @@ The find results highlight indicator number. Emitted when a result is found. It is selected and has been scrolled into view. + Arguments: + + * _`find_text`_: The text originally searched for. #### `events.FIND_WRAPPED` (string) diff --git a/modules/lua/ta_api b/modules/lua/ta_api index 1d2318b8..41e6a570 100644 --- a/modules/lua/ta_api +++ b/modules/lua/ta_api @@ -71,7 +71,7 @@ FILE_OPENED events.FILE_OPENED (string)\nEmitted after opening a file in a new b FIND events.FIND (string)\nEmitted to find text via the Find & Replace Pane.\nArguments:\n\n* _`text`_: The text to search for.\n* _`next`_: Whether or not to search forward. FIND_MATCHCASE buffer.FIND_MATCHCASE (number, Read-only)\n FIND_REGEXP buffer.FIND_REGEXP (number, Read-only)\n -FIND_RESULT_FOUND events.FIND_RESULT_FOUND (string)\nEmitted when a result is found. It is selected and has been scrolled into\nview. +FIND_RESULT_FOUND events.FIND_RESULT_FOUND (string)\nEmitted when a result is found. It is selected and has been scrolled into\nview.\nArguments:\n\n* _`find_text`_: The text originally searched for. FIND_TEXT_CHANGED events.FIND_TEXT_CHANGED (string)\nEmitted when the text in the "Find" field of the Find & Replace Pane\nchanges.\n`ui.find.find_entry_text` contains the current text. FIND_WHOLEWORD buffer.FIND_WHOLEWORD (number, Read-only)\n FIND_WORDSTART buffer.FIND_WORDSTART (number, Read-only)\n diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index c2722b0b..5450a02a 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -68,6 +68,9 @@ local M = ui.find -- @field _G.events.FIND_RESULT_FOUND (string) -- Emitted when a result is found. It is selected and has been scrolled into -- view. +-- Arguments: +-- +-- * _`find_text`_: The text originally searched for. -- @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), @@ -211,7 +214,7 @@ local function find(text, next, flags, no_wrap, wrapped) local pos = f(buffer, flags, text) view:ensure_visible_enforce_policy(buffer:line_from_position(pos)) view:scroll_range(buffer.anchor, buffer.current_pos) - if pos ~= -1 then events.emit(events.FIND_RESULT_FOUND) end + if pos ~= -1 then events.emit(events.FIND_RESULT_FOUND, text) end -- Track find text and found text for "replace all" and incremental find. find_text, found_text = text, buffer:get_sel_text() repl_text = ui.find.replace_entry_text -- save for ui.find.focus() @@ -236,9 +239,9 @@ events.connect(events.FIND_TEXT_CHANGED, function() if not M.incremental then return end return events.emit(events.FIND, M.find_entry_text, true) -- refresh end) -events.connect(events.FIND_RESULT_FOUND, function() +events.connect(events.FIND_RESULT_FOUND, function(text) -- Count and optionally highlight all occurrences. - local text, count, current = M.find_entry_text, 0, 1 + local count, current = 0, 1 buffer.search_flags = get_flags() buffer:target_whole_document() while buffer:search_in_target(text) ~= -1 do -- cgit v1.2.3