From 71f4ca67c23653d1919b0b2a151be9b6dc325ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Wed, 9 Oct 2024 19:26:28 +0200 Subject: [PATCH] Use WHOLE_WORD search option in vim mode's whole-word search (#18725) Instead of wrapping the search term with `\<...\>`, enable the `WHOLE_WORD` search option. The advantage of the search option is that it can be toggled with one click/key press (alt+w by default), and it doesn't require regex mode. Release Notes: - Vim mode's whole word search now uses the search bar's "Match whole words" option, instead of wrapping the search term with `\<...\>`. This allows easier toggling of whole-word search, and it also works without enabling the regex mode. --- crates/vim/src/normal/search.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/vim/src/normal/search.rs b/crates/vim/src/normal/search.rs index 519606b0e5..6769238407 100644 --- a/crates/vim/src/normal/search.rs +++ b/crates/vim/src/normal/search.rs @@ -269,6 +269,9 @@ impl Vim { if regex { options |= SearchOptions::REGEX; } + if whole_word { + options |= SearchOptions::WHOLE_WORD; + } if !search_bar.show(cx) { return None; } @@ -276,10 +279,7 @@ impl Vim { drop(search_bar.search("", None, cx)); return None; }; - let mut query = regex::escape(&query); - if whole_word { - query = format!(r"\<{}\>", query); - } + let query = regex::escape(&query); Some(search_bar.search(&query, Some(options), cx)) });