@@ -1523,7 +1523,8 @@ fn select_regex(cx: &mut Context) {
1523
1523
"select:" . into ( ) ,
1524
1524
Some ( reg) ,
1525
1525
ui:: completers:: none,
1526
- move |view, doc, regex, event| {
1526
+ move |editor, regex, event| {
1527
+ let ( view, doc) = current ! ( editor) ;
1527
1528
if !matches ! ( event, PromptEvent :: Update | PromptEvent :: Validate ) {
1528
1529
return ;
1529
1530
}
@@ -1544,7 +1545,8 @@ fn split_selection(cx: &mut Context) {
1544
1545
"split:" . into ( ) ,
1545
1546
Some ( reg) ,
1546
1547
ui:: completers:: none,
1547
- move |view, doc, regex, event| {
1548
+ move |editor, regex, event| {
1549
+ let ( view, doc) = current ! ( editor) ;
1548
1550
if !matches ! ( event, PromptEvent :: Update | PromptEvent :: Validate ) {
1549
1551
return ;
1550
1552
}
@@ -1566,17 +1568,16 @@ fn split_selection_on_newline(cx: &mut Context) {
1566
1568
doc. set_selection ( view. id , selection) ;
1567
1569
}
1568
1570
1569
- #[ allow( clippy:: too_many_arguments) ]
1570
1571
fn search_impl (
1571
- doc : & mut Document ,
1572
- view : & mut View ,
1572
+ editor : & mut Editor ,
1573
1573
contents : & str ,
1574
1574
regex : & Regex ,
1575
1575
movement : Movement ,
1576
1576
direction : Direction ,
1577
1577
scrolloff : usize ,
1578
1578
wrap_around : bool ,
1579
1579
) {
1580
+ let ( view, doc) = current ! ( editor) ;
1580
1581
let text = doc. text ( ) . slice ( ..) ;
1581
1582
let selection = doc. selection ( view. id ) ;
1582
1583
@@ -1606,17 +1607,25 @@ fn search_impl(
1606
1607
Direction :: Backward => regex. find_iter ( & contents[ ..start] ) . last ( ) ,
1607
1608
} ;
1608
1609
1609
- if wrap_around && mat. is_none ( ) {
1610
- mat = match direction {
1611
- Direction :: Forward => regex. find ( contents) ,
1612
- Direction :: Backward => {
1613
- offset = start;
1614
- regex. find_iter ( & contents[ start..] ) . last ( )
1615
- }
1610
+ if mat. is_none ( ) {
1611
+ if wrap_around {
1612
+ mat = match direction {
1613
+ Direction :: Forward => regex. find ( contents) ,
1614
+ Direction :: Backward => {
1615
+ offset = start;
1616
+ regex. find_iter ( & contents[ start..] ) . last ( )
1617
+ }
1618
+ } ;
1619
+ editor. set_status ( "Wrapped around document" ) ;
1620
+ } else {
1621
+ editor. set_error ( "No more matches" ) ;
1616
1622
}
1617
- // TODO: message on wraparound
1618
1623
}
1619
1624
1625
+ let ( view, doc) = current ! ( editor) ;
1626
+ let text = doc. text ( ) . slice ( ..) ;
1627
+ let selection = doc. selection ( view. id ) ;
1628
+
1620
1629
if let Some ( mat) = mat {
1621
1630
let start = text. byte_to_char ( mat. start ( ) + offset) ;
1622
1631
let end = text. byte_to_char ( mat. end ( ) + offset) ;
@@ -1696,13 +1705,12 @@ fn searcher(cx: &mut Context, direction: Direction) {
1696
1705
. map ( |comp| ( 0 .., std:: borrow:: Cow :: Owned ( comp. clone ( ) ) ) )
1697
1706
. collect ( )
1698
1707
} ,
1699
- move |view , doc , regex, event| {
1708
+ move |editor , regex, event| {
1700
1709
if !matches ! ( event, PromptEvent :: Update | PromptEvent :: Validate ) {
1701
1710
return ;
1702
1711
}
1703
1712
search_impl (
1704
- doc,
1705
- view,
1713
+ editor,
1706
1714
& contents,
1707
1715
& regex,
1708
1716
Movement :: Move ,
@@ -1718,7 +1726,7 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir
1718
1726
let count = cx. count ( ) ;
1719
1727
let config = cx. editor . config ( ) ;
1720
1728
let scrolloff = config. scrolloff ;
1721
- let ( view , doc) = current ! ( cx. editor) ;
1729
+ let ( _ , doc) = current ! ( cx. editor) ;
1722
1730
let registers = & cx. editor . registers ;
1723
1731
if let Some ( query) = registers. read ( '/' ) . and_then ( |query| query. last ( ) ) {
1724
1732
let contents = doc. text ( ) . slice ( ..) . to_string ( ) ;
@@ -1736,8 +1744,7 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir
1736
1744
{
1737
1745
for _ in 0 ..count {
1738
1746
search_impl (
1739
- doc,
1740
- view,
1747
+ cx. editor ,
1741
1748
& contents,
1742
1749
& regex,
1743
1750
movement,
@@ -1841,7 +1848,7 @@ fn global_search(cx: &mut Context) {
1841
1848
. map ( |comp| ( 0 .., std:: borrow:: Cow :: Owned ( comp. clone ( ) ) ) )
1842
1849
. collect ( )
1843
1850
} ,
1844
- move |_view , _doc , regex, event| {
1851
+ move |_editor , regex, event| {
1845
1852
if event != PromptEvent :: Validate {
1846
1853
return ;
1847
1854
}
@@ -3780,7 +3787,8 @@ fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
3780
3787
if remove { "remove:" } else { "keep:" } . into ( ) ,
3781
3788
Some ( reg) ,
3782
3789
ui:: completers:: none,
3783
- move |view, doc, regex, event| {
3790
+ move |editor, regex, event| {
3791
+ let ( view, doc) = current ! ( editor) ;
3784
3792
if !matches ! ( event, PromptEvent :: Update | PromptEvent :: Validate ) {
3785
3793
return ;
3786
3794
}
0 commit comments