File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -868,10 +868,11 @@ <h3>{% trans "No items found" %}</h3>
868868 const searchInput = document . getElementById ( 'searchInput' ) ;
869869 const filterForm = document . getElementById ( 'filterForm' ) ;
870870 let searchTimeout ;
871+ const isDesktop = window . innerWidth > 768 ;
871872
872873 if ( searchInput ) {
873- // Auto-focus if has value
874- if ( searchInput . value ) {
874+ // Auto-focus on desktop or if has value (to maintain cursor position after search)
875+ if ( isDesktop || searchInput . value ) {
875876 searchInput . focus ( ) ;
876877 searchInput . setSelectionRange ( searchInput . value . length , searchInput . value . length ) ;
877878 }
Original file line number Diff line number Diff line change @@ -628,10 +628,35 @@ <h3>{% trans "No shared items" %}</h3>
628628</ section >
629629
630630< script >
631- // Search on enter
632- document . getElementById ( 'searchInput' ) . addEventListener ( 'keypress' , function ( e ) {
633- if ( e . key === 'Enter' ) {
634- document . getElementById ( 'filterForm' ) . submit ( ) ;
631+ document . addEventListener ( "DOMContentLoaded" , function ( ) {
632+ // Real-time search with debounce
633+ const searchInput = document . getElementById ( 'searchInput' ) ;
634+ let searchTimeout ;
635+ const isDesktop = window . innerWidth > 768 ;
636+
637+ if ( searchInput ) {
638+ // Auto-focus on desktop or if has value (to maintain cursor position after search)
639+ if ( isDesktop || searchInput . value ) {
640+ searchInput . focus ( ) ;
641+ searchInput . setSelectionRange ( searchInput . value . length , searchInput . value . length ) ;
642+ }
643+
644+ searchInput . addEventListener ( 'input' , function ( ) {
645+ clearTimeout ( searchTimeout ) ;
646+ searchTimeout = setTimeout ( function ( ) {
647+ // Get current URL params
648+ const url = new URL ( window . location . href ) ;
649+ const query = searchInput . value . trim ( ) ;
650+
651+ if ( query ) {
652+ url . searchParams . set ( 'query' , query ) ;
653+ } else {
654+ url . searchParams . delete ( 'query' ) ;
655+ }
656+
657+ window . location . href = url . toString ( ) ;
658+ } , 400 ) ;
659+ } ) ;
635660 }
636661} ) ;
637662
You can’t perform that action at this time.
0 commit comments