@@ -806,6 +806,7 @@ void FindInFilesPanel::set_replace_text(const String &text) {
806806
807807void FindInFilesPanel::clear () {
808808 _file_items.clear ();
809+ _file_items_results_count.clear ();
809810 _result_items.clear ();
810811 _results_display->clear ();
811812 _results_display->create_item (); // Root
@@ -893,8 +894,10 @@ void FindInFilesPanel::_on_result_found(const String &fpath, int line_number, in
893894 file_item->set_expand_right (0 , true );
894895
895896 _file_items[fpath] = file_item;
897+ _file_items_results_count[file_item] = 1 ;
896898 } else {
897899 file_item = E->value ;
900+ _file_items_results_count[file_item]++;
898901 }
899902
900903 Color file_item_color = _results_display->get_theme_color (SceneStringName (font_color)) * Color (1 , 1 , 1 , 0.67 );
@@ -1045,26 +1048,30 @@ void FindInFilesPanel::_on_replace_all_clicked() {
10451048}
10461049
10471050void FindInFilesPanel::_on_button_clicked (TreeItem *p_item, int p_column, int p_id, int p_mouse_button_index) {
1048- const String file_path = p_item->get_text (0 );
1049-
10501051 _result_items.erase (p_item);
1051- if (_file_items. find (file_path )) {
1052- TreeItem *file_result = _file_items. get (file_path );
1053- int match_count = file_result ->get_child_count ();
1052+ if (_file_items_results_count. has (p_item )) {
1053+ const String file_path = p_item-> get_metadata ( 0 );
1054+ int match_count = p_item ->get_child_count ();
10541055
10551056 for (int i = 0 ; i < match_count; i++) {
1056- TreeItem *child_item = file_result ->get_child (i);
1057+ TreeItem *child_item = p_item ->get_child (i);
10571058 _result_items.erase (child_item);
10581059 }
10591060
1060- file_result ->clear_children ();
1061+ p_item ->clear_children ();
10611062 _file_items.erase (file_path);
1063+ _file_items_results_count.erase (p_item);
10621064 }
10631065
10641066 TreeItem *item_parent = p_item->get_parent ();
1065- if (item_parent && item_parent->get_child_count () < 2 ) {
1066- _file_items.erase (item_parent->get_text (0 ));
1067- get_tree ()->queue_delete (item_parent);
1067+ if (item_parent) {
1068+ if (_file_items_results_count.has (item_parent)) {
1069+ _file_items_results_count[item_parent]--;
1070+ }
1071+ if (item_parent->get_child_count () < 2 ) {
1072+ _file_items.erase (item_parent->get_metadata (0 ));
1073+ get_tree ()->queue_delete (item_parent);
1074+ }
10681075 }
10691076 get_tree ()->queue_delete (p_item);
10701077 update_matches_text ();
@@ -1184,6 +1191,13 @@ void FindInFilesPanel::update_matches_text() {
11841191 }
11851192
11861193 _status_label->set_text (results_text);
1194+
1195+ TreeItem *file_item = _results_display->get_root ()->get_first_child ();
1196+ while (file_item) {
1197+ int file_matches_count = _file_items_results_count[file_item];
1198+ file_item->set_text (0 , (String)file_item->get_metadata (0 ) + " (" + vformat (TTRN (" %d match" , " %d matches" , file_matches_count), file_matches_count) + " )" );
1199+ file_item = file_item->get_next ();
1200+ }
11871201}
11881202
11891203void FindInFilesPanel::_bind_methods () {
0 commit comments