@@ -208,8 +208,8 @@ impl Window {
208208 imp. action_previous . borrow_mut ( ) . replace ( action_previous) ;
209209 imp. action_next . borrow_mut ( ) . replace ( action_next) ;
210210
211- self_action ! ( self , "new-tab" , add_tab_focused ) ;
212- self_action ! ( self , "show-bookmarks" , add_tab_focused ) ;
211+ self_action ! ( self , "new-tab" , new_tab ) ;
212+ self_action ! ( self , "show-bookmarks" , show_bookmarks ) ;
213213 self_action ! ( self , "bookmark-current" , bookmark_current) ;
214214 self_action ! ( self , "close-tab" , close_tab) ;
215215 self_action ! ( self , "focus-url-bar" , focus_url_bar) ;
@@ -277,6 +277,10 @@ impl Window {
277277 false ,
278278 clone ! ( @weak self as this => @default -panic, move |_| {
279279 this. set_special_color_from_hash( ) ;
280+ let bar = this. active_url_bar( ) ;
281+ if bar. focus_child( ) . is_none( ) {
282+ bar. set_text( & this. url( ) ) ;
283+ }
280284 None
281285 } ) ,
282286 ) ;
@@ -384,6 +388,12 @@ impl Window {
384388 fn page_switched ( & self , tab_view : & adw:: TabView ) {
385389 let imp = self . imp ( ) ;
386390 let mut btp = imp. binded_tab_properties . borrow_mut ( ) ;
391+
392+ // Unset the focus from the url_bar
393+ if let Some ( r) = tab_view. root ( ) {
394+ r. set_focus ( None :: < & gtk:: Widget > )
395+ }
396+
387397 if let Some ( page) = tab_view. selected_page ( ) {
388398 let tab = self . inner_tab ( & page) ;
389399
@@ -430,11 +440,15 @@ impl Window {
430440 ] ) ;
431441 } ;
432442 }
433- fn add_tab_focused ( & self ) {
443+ fn new_tab ( & self ) {
444+ self . show_bookmarks ( ) ;
445+ self . active_url_bar ( ) . grab_focus ( ) ;
446+ }
447+ fn show_bookmarks ( & self ) {
434448 let imp = self . imp ( ) ;
435449 let p = self . add_tab ( ) ;
436- self . inner_tab ( & p) . spawn_open_url ( bookmarks_url ( ) ) ;
437450 imp. tab_view . set_selected_page ( & p) ;
451+ self . inner_tab ( & p) . spawn_open_url ( bookmarks_url ( ) ) ;
438452 }
439453 fn close_tab ( & self ) {
440454 let imp = self . imp ( ) ;
@@ -444,14 +458,17 @@ impl Window {
444458 std:: process:: exit ( 0 ) ; // TODO: maybe there's a better way for gtk apps...
445459 }
446460 }
447- fn focus_url_bar ( & self ) {
461+ fn active_url_bar ( & self ) -> & gtk :: SearchEntry {
448462 let imp = self . imp ( ) ;
449463 if self . is_small_screen ( ) {
450- imp. small_url_bar . grab_focus ( ) ;
464+ & * imp. small_url_bar
451465 } else {
452- imp. url_bar . grab_focus ( ) ;
466+ & * imp. url_bar
453467 }
454468 }
469+ fn focus_url_bar ( & self ) {
470+ self . active_url_bar ( ) . grab_focus ( ) ;
471+ }
455472
456473 async fn append_bookmark ( url : & str ) -> anyhow:: Result < ( ) > {
457474 let mut file = async_fs:: OpenOptions :: new ( )
0 commit comments