From ffb423bc763e8e743551b77f3447f7d5d6fb9507 Mon Sep 17 00:00:00 2001 From: Maganty Rushyendra Date: Mon, 15 Jun 2020 11:39:36 +0800 Subject: [PATCH] Fix match count for whole word search in editor Check if a match borders a new line char when incrementing match counts. (cherry picked from commit 91bdc77d47eba2a0c74c07eb57ce5ee14538b535) --- editor/code_editor.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 4416a1681fd..336d548dbea 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -319,16 +319,17 @@ void FindReplaceBar::_update_results_count() { int pos = is_case_sensitive() ? full_text.find(searched, from_pos) : full_text.findn(searched, from_pos); if (pos == -1) break; + int pos_subsequent = pos + searched.length(); if (is_whole_words()) { from_pos = pos + 1; // Making sure we won't hit the same match next time, if we get out via a continue. - if (pos > 0 && !is_symbol(full_text[pos - 1])) + if (pos > 0 && !(is_symbol(full_text[pos - 1]) || full_text[pos - 1] == '\n')) continue; - if (pos + searched.length() < full_text.length() && !is_symbol(full_text[pos + searched.length()])) + if (pos_subsequent < full_text.length() && !(is_symbol(full_text[pos_subsequent]) || full_text[pos_subsequent] == '\n')) continue; } results_count++; - from_pos = pos + searched.length(); + from_pos = pos_subsequent; } }