11use iced:: highlighter;
22use iced:: keyboard;
33use iced:: widget:: {
4- button, center_x, column, container, operation, pick_list, row , space ,
5- text, text_editor, toggler, tooltip,
4+ self , button, center_x, column, container, operation:: focus , pick_list,
5+ row , space , text, text_editor, toggler, tooltip,
66} ;
77use iced:: { Center , Element , Fill , Font , Task , Theme } ;
88
@@ -20,6 +20,7 @@ pub fn main() -> iced::Result {
2020}
2121
2222struct Editor {
23+ editor_id : widget:: Id ,
2324 file : Option < PathBuf > ,
2425 content : text_editor:: Content ,
2526 theme : highlighter:: Theme ,
@@ -42,8 +43,10 @@ enum Message {
4243
4344impl Editor {
4445 fn new ( ) -> ( Self , Task < Message > ) {
46+ let id = widget:: Id :: unique ( ) ;
4547 (
4648 Self {
49+ editor_id : id. clone ( ) ,
4750 file : None ,
4851 content : text_editor:: Content :: new ( ) ,
4952 theme : highlighter:: Theme :: SolarizedDark ,
@@ -59,7 +62,7 @@ impl Editor {
5962 ) ) ,
6063 Message :: FileOpened ,
6164 ) ,
62- operation :: focus_next ( ) ,
65+ focus ( id ) ,
6366 ] ) ,
6467 )
6568 }
@@ -196,6 +199,7 @@ impl Editor {
196199 column ! [
197200 controls,
198201 text_editor( & self . content)
202+ . id( self . editor_id. clone( ) )
199203 . height( Fill )
200204 . on_action( Message :: ActionPerformed )
201205 . wrapping( if self . word_wrap {
0 commit comments