@@ -459,29 +459,27 @@ float CreateDialog::_score_type(const String &p_type, const String &p_search) co
459459 return 1 .0f ;
460460 }
461461
462- const String &type_name = p_type.get_slicec (' ' , 0 );
463-
464- float inverse_length = 1 .f / float (type_name.length ());
462+ float inverse_length = 1 .f / float (p_type.length ());
465463
466464 // Favor types where search term is a substring close to the start of the type.
467465 float w = 0 .5f ;
468- int pos = type_name .findn (p_search);
466+ int pos = p_type .findn (p_search);
469467 float score = (pos > -1 ) ? 1 .0f - w * MIN (1 , 3 * pos * inverse_length) : MAX (0 .f , .9f - w);
470468
471469 // Favor shorter items: they resemble the search term more.
472470 w = 0 .9f ;
473471 score *= (1 - w) + w * MIN (1 .0f , p_search.length () * inverse_length);
474472
475- score *= _is_type_preferred (type_name ) ? 1 .0f : 0 .9f ;
473+ score *= _is_type_preferred (p_type ) ? 1 .0f : 0 .9f ;
476474
477475 // Add score for being a favorite type.
478- score *= favorite_list.has (type_name ) ? 1 .0f : 0 .8f ;
476+ score *= favorite_list.has (p_type ) ? 1 .0f : 0 .8f ;
479477
480478 // Look through at most 5 recent items
481479 bool in_recent = false ;
482480 constexpr int RECENT_COMPLETION_SIZE = 5 ;
483481 for (int i = 0 ; i < MIN (RECENT_COMPLETION_SIZE - 1 , recent->get_item_count ()); i++) {
484- if (recent->get_item_text (i) == type_name ) {
482+ if (recent->get_item_text (i) == p_type ) {
485483 in_recent = true ;
486484 break ;
487485 }
@@ -680,7 +678,7 @@ void CreateDialog::_favorite_toggled() {
680678 return ;
681679 }
682680
683- String name = item->get_text (0 );
681+ String name = item->get_text (0 ). get_slicec ( ' ' , 0 ) ;
684682
685683 if (favorite_list.has (name)) {
686684 favorite_list.erase (name);
@@ -694,7 +692,7 @@ void CreateDialog::_favorite_toggled() {
694692}
695693
696694void CreateDialog::_history_selected (int p_idx) {
697- search_box->set_text (recent->get_item_text (p_idx). get_slicec ( ' ' , 0 ) );
695+ search_box->set_text (recent->get_item_text (p_idx));
698696 favorites->deselect_all ();
699697 _update_search ();
700698}
@@ -705,7 +703,7 @@ void CreateDialog::_favorite_selected() {
705703 return ;
706704 }
707705
708- search_box->set_text (item->get_text (0 ). get_slicec ( ' ' , 0 ) );
706+ search_box->set_text (item->get_text (0 ));
709707 recent->deselect_all ();
710708 _update_search ();
711709}
@@ -801,20 +799,18 @@ void CreateDialog::_save_and_update_favorite_list() {
801799 {
802800 Ref<FileAccess> f = FileAccess::open (EditorPaths::get_singleton ()->get_project_settings_dir ().path_join (" favorites." + base_type), FileAccess::WRITE);
803801 if (f.is_valid ()) {
804- for (int i = 0 ; i < favorite_list.size (); i++) {
805- String l = favorite_list[i];
806- String name = l.get_slicec (' ' , 0 );
802+ for (const String &name : favorite_list) {
807803 if (!EditorNode::get_editor_data ().is_type_recognized (name)) {
808804 continue ;
809805 }
810- f->store_line (l );
806+ f->store_line (name );
811807
812808 if (_is_class_disabled_by_feature_profile (name)) {
813809 continue ;
814810 }
815811
816812 TreeItem *ti = favorites->create_item (root);
817- ti->set_text (0 , l );
813+ ti->set_text (0 , name );
818814 ti->set_icon (0 , EditorNode::get_singleton ()->get_class_icon (name));
819815 }
820816 }
@@ -828,22 +824,21 @@ void CreateDialog::_load_favorites_and_history() {
828824 Ref<FileAccess> f = FileAccess::open (dir.path_join (" create_recent." + base_type), FileAccess::READ);
829825 if (f.is_valid ()) {
830826 while (!f->eof_reached ()) {
831- String l = f->get_line ().strip_edges ();
832- String name = l.get_slicec (' ' , 0 );
827+ String name = f->get_line ().strip_edges ();
833828
834829 if (EditorNode::get_editor_data ().is_type_recognized (name) && !_is_class_disabled_by_feature_profile (name)) {
835- recent->add_item (l , EditorNode::get_singleton ()->get_class_icon (name));
830+ recent->add_item (name , EditorNode::get_singleton ()->get_class_icon (name));
836831 }
837832 }
838833 }
839834
840835 f = FileAccess::open (dir.path_join (" favorites." + base_type), FileAccess::READ);
841836 if (f.is_valid ()) {
842837 while (!f->eof_reached ()) {
843- String l = f->get_line ().strip_edges ();
838+ String name = f->get_line ().strip_edges ();
844839
845- if (!l .is_empty ()) {
846- favorite_list.push_back (l );
840+ if (!name .is_empty ()) {
841+ favorite_list.push_back (name );
847842 }
848843 }
849844 }
0 commit comments