@@ -250,6 +250,7 @@ impl MappableCommand {
250
250
extend_search_next, "Add next search match to selection" ,
251
251
extend_search_prev, "Add previous search match to selection" ,
252
252
search_selection, "Use current selection as search pattern" ,
253
+ make_search_word_bounded, "Modify current search to make it word bounded" ,
253
254
global_search, "Global search in workspace folder" ,
254
255
extend_line, "Select current line, if already selected, extend to another line based on the anchor" ,
255
256
extend_line_below, "Select current line, if already selected, extend to next line" ,
@@ -1809,6 +1810,35 @@ fn search_selection(cx: &mut Context) {
1809
1810
cx. editor . set_status ( msg) ;
1810
1811
}
1811
1812
1813
+ fn make_search_word_bounded ( cx : & mut Context ) {
1814
+ let regex = match cx. editor . registers . last ( '/' ) {
1815
+ Some ( regex) => regex,
1816
+ None => return ,
1817
+ } ;
1818
+ let start_anchored = regex. starts_with ( "\\ b" ) ;
1819
+ let end_anchored = regex. ends_with ( "\\ b" ) ;
1820
+
1821
+ if start_anchored && end_anchored {
1822
+ return ;
1823
+ }
1824
+
1825
+ let mut new_regex = String :: with_capacity (
1826
+ regex. len ( ) + if start_anchored { 0 } else { 2 } + if end_anchored { 0 } else { 2 } ,
1827
+ ) ;
1828
+
1829
+ if !start_anchored {
1830
+ new_regex. push_str ( "\\ b" ) ;
1831
+ }
1832
+ new_regex. push_str ( regex) ;
1833
+ if !end_anchored {
1834
+ new_regex. push_str ( "\\ b" ) ;
1835
+ }
1836
+
1837
+ let msg = format ! ( "register '{}' set to '{}'" , '/' , & new_regex) ;
1838
+ cx. editor . registers . get_mut ( '/' ) . push ( new_regex) ;
1839
+ cx. editor . set_status ( msg) ;
1840
+ }
1841
+
1812
1842
fn global_search ( cx : & mut Context ) {
1813
1843
#[ derive( Debug ) ]
1814
1844
struct FileResult {
0 commit comments