@@ -577,8 +577,12 @@ void AbstractView::keydown_event(KeyEvent& event)
577
577
n_code_points--;
578
578
sb.append_code_point (*it);
579
579
}
580
- do_search (sb.to_string ());
581
- start_highlighted_search_timer ();
580
+ auto index = find_next_search_match (sb.string_view ());
581
+ if (index.is_valid ()) {
582
+ m_highlighted_search = sb.to_string ();
583
+ highlight_search (index);
584
+ start_highlighted_search_timer ();
585
+ }
582
586
} else {
583
587
stop_highlighted_search_timer ();
584
588
}
@@ -597,8 +601,13 @@ void AbstractView::keydown_event(KeyEvent& event)
597
601
StringBuilder sb;
598
602
sb.append (m_highlighted_search);
599
603
sb.append_code_point (event.code_point ());
600
- do_search (sb.to_string ());
601
- start_highlighted_search_timer ();
604
+
605
+ auto index = find_next_search_match (sb.string_view ());
606
+ if (index.is_valid ()) {
607
+ m_highlighted_search = sb.to_string ();
608
+ highlight_search (index);
609
+ start_highlighted_search_timer ();
610
+ }
602
611
603
612
event.accept ();
604
613
return ;
@@ -632,22 +641,25 @@ void AbstractView::start_highlighted_search_timer()
632
641
m_highlighted_search_timer->restart ();
633
642
}
634
643
635
- void AbstractView::do_search (String&& searching )
644
+ ModelIndex AbstractView::find_next_search_match (StringView const search )
636
645
{
637
- if (searching.is_empty () || !model ()) {
638
- stop_highlighted_search_timer ();
639
- return ;
640
- }
646
+ if (search.is_empty ())
647
+ return {};
641
648
642
- auto found_indices = model ()->matches (searching, Model::MatchesFlag::FirstMatchOnly | Model::MatchesFlag::MatchAtStart | Model::MatchesFlag::CaseInsensitive, model ()->parent_index (cursor_index ()));
643
- if (!found_indices.is_empty () && found_indices[0 ].is_valid ()) {
644
- auto & index = found_indices[0 ];
645
- m_highlighted_search_index = index;
646
- m_highlighted_search = move (searching);
647
- set_selection (index);
648
- scroll_into_view (index);
649
- update ();
650
- }
649
+ auto found_indices = model ()->matches (search, Model::MatchesFlag::FirstMatchOnly | Model::MatchesFlag::MatchAtStart | Model::MatchesFlag::CaseInsensitive, model ()->parent_index (cursor_index ()));
650
+
651
+ if (found_indices.is_empty ())
652
+ return {};
653
+
654
+ return found_indices[0 ];
655
+ }
656
+
657
+ void AbstractView::highlight_search (ModelIndex const index)
658
+ {
659
+ m_highlighted_search_index = index;
660
+ set_selection (index);
661
+ scroll_into_view (index);
662
+ update ();
651
663
}
652
664
653
665
bool AbstractView::is_searchable () const
0 commit comments