From 62afba09bf6e8556ee472c749b134da99cfcf1c1 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Fri, 27 May 2016 19:39:15 +0200 Subject: [PATCH] Improve the Find next/previous commands - Finding is asynchronous. This commit makes sure to wait until the finding is done before sending notifications (such as "Phrase not found"). This makes the notifications more reliable. - Prevent the find bar from re-opening if there are no matches. Fixes #739. --- extension/lib/commands.coffee | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/extension/lib/commands.coffee b/extension/lib/commands.coffee index 2d5ed8a..e40ef45 100644 --- a/extension/lib/commands.coffee +++ b/extension/lib/commands.coffee @@ -729,9 +729,19 @@ helper_find_again = (direction, {vim}) -> helper_mark_last_scroll_position(vim) helper_find_from_top_of_viewport(vim, direction, -> findBar._findField.value = findStorage.lastSearchString + + # Temporarily hack `.onFindResult` to be able to know when the asynchronous + # `.onFindAgainCommand` is done. + originalOnFindResult = findBar.onFindResult + findBar.onFindResult = (data) -> + # Prevent the find bar from re-opening if there are no matches. + data.storeResult = false + findBar.onFindResult = originalOnFindResult + findBar.onFindResult(data) + message = findBar._findStatusDesc.textContent + vim.notify(message) if message + findBar.onFindAgainCommand(not direction) - message = findBar._findStatusDesc.textContent - vim.notify(message) if message ) commands.find_next = helper_find_again.bind(null, FORWARD) -- 2.39.3