@@ -500,7 +500,7 @@ impl TextEdit<'_> {
500500 // .unwrap_or_else(|| ui.style().interact(&response).text_color()); // too bright
501501 . unwrap_or_else ( || ui. visuals ( ) . widgets . inactive . text_color ( ) ) ;
502502
503- let prev_text = text. as_str ( ) . to_owned ( ) ;
503+ let prev_text = text. clone_to_arc ( ) ;
504504 let hint_text_str = hint_text. text ( ) . to_owned ( ) ;
505505
506506 let font_id = font_selection. resolve ( ui. style ( ) ) ;
@@ -516,7 +516,8 @@ impl TextEdit<'_> {
516516
517517 let font_id_clone = font_id. clone ( ) ;
518518 let mut default_layouter = move |ui : & Ui , text : & dyn TextBuffer , wrap_width : f32 | {
519- let text = mask_if_password ( password, text. as_str ( ) ) ;
519+ // TODO: Keep as Arc<str>!
520+ let text = ( * mask_if_password ( password, text. clone_to_arc ( ) ) ) . to_owned ( ) ;
520521 let layout_job = if multiline {
521522 LayoutJob :: simple ( text, font_id_clone. clone ( ) , text_color, wrap_width)
522523 } else {
@@ -819,8 +820,8 @@ impl TextEdit<'_> {
819820 response. widget_info ( || {
820821 WidgetInfo :: text_edit (
821822 ui. is_enabled ( ) ,
822- mask_if_password ( password, prev_text. as_str ( ) ) ,
823- mask_if_password ( password, text. as_str ( ) ) ,
823+ mask_if_password ( password, prev_text. clone ( ) ) ,
824+ mask_if_password ( password, text. clone_to_arc ( ) ) ,
824825 hint_text_str. as_str ( ) ,
825826 )
826827 } ) ;
@@ -830,15 +831,15 @@ impl TextEdit<'_> {
830831 let info = WidgetInfo :: text_selection_changed (
831832 ui. is_enabled ( ) ,
832833 char_range,
833- mask_if_password ( password, text. as_str ( ) ) ,
834+ mask_if_password ( password, text. clone_to_arc ( ) ) ,
834835 ) ;
835836 response. output_event ( OutputEvent :: TextSelectionChanged ( info) ) ;
836837 } else {
837838 response. widget_info ( || {
838839 WidgetInfo :: text_edit (
839840 ui. is_enabled ( ) ,
840- mask_if_password ( password, prev_text. as_str ( ) ) ,
841- mask_if_password ( password, text. as_str ( ) ) ,
841+ mask_if_password ( password, prev_text. clone ( ) ) ,
842+ mask_if_password ( password, text. clone_to_arc ( ) ) ,
842843 hint_text_str. as_str ( ) ,
843844 )
844845 } ) ;
@@ -875,7 +876,7 @@ impl TextEdit<'_> {
875876 }
876877}
877878
878- fn mask_if_password ( is_password : bool , text : & str ) -> String {
879+ fn mask_if_password ( is_password : bool , text : Arc < str > ) -> Arc < str > {
879880 fn mask_password ( text : & str ) -> String {
880881 std:: iter:: repeat_n (
881882 epaint:: text:: PASSWORD_REPLACEMENT_CHAR ,
@@ -885,9 +886,9 @@ fn mask_if_password(is_password: bool, text: &str) -> String {
885886 }
886887
887888 if is_password {
888- mask_password ( text)
889+ mask_password ( & text) . into ( )
889890 } else {
890- text. to_owned ( )
891+ text
891892 }
892893}
893894
@@ -916,10 +917,10 @@ fn events(
916917
917918 // We feed state to the undoer both before and after handling input
918919 // so that the undoer creates automatic saves even when there are no events for a while.
919- state. undoer . lock ( ) . feed_state (
920- ui . input ( |i| i . time ) ,
921- & ( cursor_range , text . as_str ( ) . to_owned ( ) ) ,
922- ) ;
920+ state
921+ . undoer
922+ . lock ( )
923+ . feed_state ( ui . input ( |i| i . time ) , & ( cursor_range , text . clone_to_arc ( ) ) ) ;
923924
924925 let copy_if_not_password = |ui : & Ui , text : String | {
925926 if !password {
@@ -1030,7 +1031,7 @@ fn events(
10301031 if let Some ( ( redo_ccursor_range, redo_txt) ) = state
10311032 . undoer
10321033 . lock ( )
1033- . redo ( & ( cursor_range, text. as_str ( ) . to_owned ( ) ) )
1034+ . redo ( & ( cursor_range, text. clone_to_arc ( ) ) )
10341035 {
10351036 text. replace_with ( redo_txt) ;
10361037 Some ( * redo_ccursor_range)
@@ -1048,7 +1049,7 @@ fn events(
10481049 if let Some ( ( undo_ccursor_range, undo_txt) ) = state
10491050 . undoer
10501051 . lock ( )
1051- . undo ( & ( cursor_range, text. as_str ( ) . to_owned ( ) ) )
1052+ . undo ( & ( cursor_range, text. clone_to_arc ( ) ) )
10521053 {
10531054 text. replace_with ( undo_txt) ;
10541055 Some ( * undo_ccursor_range)
@@ -1126,10 +1127,10 @@ fn events(
11261127
11271128 state. cursor . set_char_range ( Some ( cursor_range) ) ;
11281129
1129- state. undoer . lock ( ) . feed_state (
1130- ui . input ( |i| i . time ) ,
1131- & ( cursor_range , text . as_str ( ) . to_owned ( ) ) ,
1132- ) ;
1130+ state
1131+ . undoer
1132+ . lock ( )
1133+ . feed_state ( ui . input ( |i| i . time ) , & ( cursor_range , text . clone_to_arc ( ) ) ) ;
11331134
11341135 ( any_change, cursor_range)
11351136}
0 commit comments