@@ -1520,7 +1520,8 @@ fn select_regex(cx: &mut Context) {
1520
1520
"select:" . into ( ) ,
1521
1521
Some ( reg) ,
1522
1522
ui:: completers:: none,
1523
- move |view, doc, regex, event| {
1523
+ move |editor, regex, event| {
1524
+ let ( view, doc) = current ! ( editor) ;
1524
1525
if !matches ! ( event, PromptEvent :: Update | PromptEvent :: Validate ) {
1525
1526
return ;
1526
1527
}
@@ -1541,7 +1542,8 @@ fn split_selection(cx: &mut Context) {
1541
1542
"split:" . into ( ) ,
1542
1543
Some ( reg) ,
1543
1544
ui:: completers:: none,
1544
- move |view, doc, regex, event| {
1545
+ move |editor, regex, event| {
1546
+ let ( view, doc) = current ! ( editor) ;
1545
1547
if !matches ! ( event, PromptEvent :: Update | PromptEvent :: Validate ) {
1546
1548
return ;
1547
1549
}
@@ -1563,17 +1565,16 @@ fn split_selection_on_newline(cx: &mut Context) {
1563
1565
doc. set_selection ( view. id , selection) ;
1564
1566
}
1565
1567
1566
- #[ allow( clippy:: too_many_arguments) ]
1567
1568
fn search_impl (
1568
- doc : & mut Document ,
1569
- view : & mut View ,
1569
+ editor : & mut Editor ,
1570
1570
contents : & str ,
1571
1571
regex : & Regex ,
1572
1572
movement : Movement ,
1573
1573
direction : Direction ,
1574
1574
scrolloff : usize ,
1575
1575
wrap_around : bool ,
1576
1576
) {
1577
+ let ( view, doc) = current ! ( editor) ;
1577
1578
let text = doc. text ( ) . slice ( ..) ;
1578
1579
let selection = doc. selection ( view. id ) ;
1579
1580
@@ -1603,17 +1604,25 @@ fn search_impl(
1603
1604
Direction :: Backward => regex. find_iter ( & contents[ ..start] ) . last ( ) ,
1604
1605
} ;
1605
1606
1606
- if wrap_around && mat. is_none ( ) {
1607
- mat = match direction {
1608
- Direction :: Forward => regex. find ( contents) ,
1609
- Direction :: Backward => {
1610
- offset = start;
1611
- regex. find_iter ( & contents[ start..] ) . last ( )
1612
- }
1607
+ if mat. is_none ( ) {
1608
+ if wrap_around {
1609
+ mat = match direction {
1610
+ Direction :: Forward => regex. find ( contents) ,
1611
+ Direction :: Backward => {
1612
+ offset = start;
1613
+ regex. find_iter ( & contents[ start..] ) . last ( )
1614
+ }
1615
+ } ;
1616
+ editor. set_status ( "Wrapped around document" ) ;
1617
+ } else {
1618
+ editor. set_error ( "No more matches" ) ;
1613
1619
}
1614
- // TODO: message on wraparound
1615
1620
}
1616
1621
1622
+ let ( view, doc) = current ! ( editor) ;
1623
+ let text = doc. text ( ) . slice ( ..) ;
1624
+ let selection = doc. selection ( view. id ) ;
1625
+
1617
1626
if let Some ( mat) = mat {
1618
1627
let start = text. byte_to_char ( mat. start ( ) + offset) ;
1619
1628
let end = text. byte_to_char ( mat. end ( ) + offset) ;
@@ -1689,13 +1698,12 @@ fn searcher(cx: &mut Context, direction: Direction) {
1689
1698
. map ( |comp| ( 0 .., std:: borrow:: Cow :: Owned ( comp. clone ( ) ) ) )
1690
1699
. collect ( )
1691
1700
} ,
1692
- move |view , doc , regex, event| {
1701
+ move |editor , regex, event| {
1693
1702
if !matches ! ( event, PromptEvent :: Update | PromptEvent :: Validate ) {
1694
1703
return ;
1695
1704
}
1696
1705
search_impl (
1697
- doc,
1698
- view,
1706
+ editor,
1699
1707
& contents,
1700
1708
& regex,
1701
1709
Movement :: Move ,
@@ -1711,7 +1719,7 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir
1711
1719
let count = cx. count ( ) ;
1712
1720
let config = cx. editor . config ( ) ;
1713
1721
let scrolloff = config. scrolloff ;
1714
- let ( view , doc) = current ! ( cx. editor) ;
1722
+ let ( _ , doc) = current ! ( cx. editor) ;
1715
1723
let registers = & cx. editor . registers ;
1716
1724
if let Some ( query) = registers. read ( '/' ) . and_then ( |query| query. last ( ) ) {
1717
1725
let contents = doc. text ( ) . slice ( ..) . to_string ( ) ;
@@ -1729,8 +1737,7 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir
1729
1737
{
1730
1738
for _ in 0 ..count {
1731
1739
search_impl (
1732
- doc,
1733
- view,
1740
+ cx. editor ,
1734
1741
& contents,
1735
1742
& regex,
1736
1743
movement,
@@ -1834,7 +1841,7 @@ fn global_search(cx: &mut Context) {
1834
1841
. map ( |comp| ( 0 .., std:: borrow:: Cow :: Owned ( comp. clone ( ) ) ) )
1835
1842
. collect ( )
1836
1843
} ,
1837
- move |_view , _doc , regex, event| {
1844
+ move |_editor , regex, event| {
1838
1845
if event != PromptEvent :: Validate {
1839
1846
return ;
1840
1847
}
@@ -3773,7 +3780,8 @@ fn keep_or_remove_selections_impl(cx: &mut Context, remove: bool) {
3773
3780
if remove { "remove:" } else { "keep:" } . into ( ) ,
3774
3781
Some ( reg) ,
3775
3782
ui:: completers:: none,
3776
- move |view, doc, regex, event| {
3783
+ move |editor, regex, event| {
3784
+ let ( view, doc) = current ! ( editor) ;
3777
3785
if !matches ! ( event, PromptEvent :: Update | PromptEvent :: Validate ) {
3778
3786
return ;
3779
3787
}
0 commit comments