@@ -209,8 +209,8 @@ impl Window {
209209 imp. action_previous . borrow_mut ( ) . replace ( action_previous) ;
210210 imp. action_next . borrow_mut ( ) . replace ( action_next) ;
211211
212- self_action ! ( self , "new-tab" , add_tab_focused ) ;
213- self_action ! ( self , "show-bookmarks" , add_tab_focused ) ;
212+ self_action ! ( self , "new-tab" , new_tab ) ;
213+ self_action ! ( self , "show-bookmarks" , show_bookmarks ) ;
214214 self_action ! ( self , "bookmark-current" , bookmark_current) ;
215215 self_action ! ( self , "close-tab" , close_tab) ;
216216 self_action ! ( self , "focus-url-bar" , focus_url_bar) ;
@@ -294,6 +294,10 @@ impl Window {
294294 false ,
295295 clone ! ( @weak self as this => @default -panic, move |_| {
296296 this. set_special_color_from_hash( ) ;
297+ let bar = this. active_url_bar( ) ;
298+ if bar. focus_child( ) . is_none( ) {
299+ bar. set_text( & this. url( ) ) ;
300+ }
297301 None
298302 } ) ,
299303 ) ;
@@ -401,6 +405,12 @@ impl Window {
401405 fn page_switched ( & self , tab_view : & adw:: TabView ) {
402406 let imp = self . imp ( ) ;
403407 let mut btp = imp. binded_tab_properties . borrow_mut ( ) ;
408+
409+ // Unset the focus from the url_bar
410+ if let Some ( r) = tab_view. root ( ) {
411+ r. set_focus ( None :: < & gtk:: Widget > )
412+ }
413+
404414 if let Some ( page) = tab_view. selected_page ( ) {
405415 let tab = self . inner_tab ( & page) ;
406416
@@ -447,11 +457,15 @@ impl Window {
447457 ] ) ;
448458 } ;
449459 }
450- fn add_tab_focused ( & self ) {
460+ fn new_tab ( & self ) {
461+ self . show_bookmarks ( ) ;
462+ self . active_url_bar ( ) . grab_focus ( ) ;
463+ }
464+ fn show_bookmarks ( & self ) {
451465 let imp = self . imp ( ) ;
452466 let p = self . add_tab ( ) ;
453- self . inner_tab ( & p) . spawn_open_url ( bookmarks_url ( ) ) ;
454467 imp. tab_view . set_selected_page ( & p) ;
468+ self . inner_tab ( & p) . spawn_open_url ( bookmarks_url ( ) ) ;
455469 }
456470 fn close_tab ( & self ) {
457471 let imp = self . imp ( ) ;
@@ -461,14 +475,17 @@ impl Window {
461475 std:: process:: exit ( 0 ) ; // TODO: maybe there's a better way for gtk apps...
462476 }
463477 }
464- fn focus_url_bar ( & self ) {
478+ fn active_url_bar ( & self ) -> & gtk :: SearchEntry {
465479 let imp = self . imp ( ) ;
466480 if self . is_small_screen ( ) {
467- imp. small_url_bar . grab_focus ( ) ;
481+ & * imp. small_url_bar
468482 } else {
469- imp. url_bar . grab_focus ( ) ;
483+ & * imp. url_bar
470484 }
471485 }
486+ fn focus_url_bar ( & self ) {
487+ self . active_url_bar ( ) . grab_focus ( ) ;
488+ }
472489
473490 async fn append_bookmark ( url : & str ) -> anyhow:: Result < ( ) > {
474491 let mut file = async_fs:: OpenOptions :: new ( )
0 commit comments