@@ -123,16 +123,31 @@ export function CustomizeSidebarDialog({
123123} ) {
124124 const [ state , setState ] = useState < DialogState > ( ( ) => buildState ( sections , prefs ) ) ;
125125
126- const orderedSections = state . sectionOrder
127- . map ( ( id ) => sections . find ( ( section ) => section . id === id ) )
128- . filter ( ( section ) : section is CustomizeSidebarSection => section !== undefined ) ;
129-
130- const moveSection = ( index : number , direction : - 1 | 1 ) => {
126+ // The Favorites section disappears with its last staged-removed favorite, matching the side
127+ // menu (which hides the section when empty)
128+ const displayedSections = ( current : DialogState ) =>
129+ current . sectionOrder
130+ . map ( ( id ) => sections . find ( ( section ) => section . id === id ) )
131+ . filter ( ( section ) : section is CustomizeSidebarSection => section !== undefined )
132+ . filter (
133+ ( section ) =>
134+ section . id !== FAVORITES_SECTION_ID ||
135+ section . items . some ( ( item ) => ! current . removed . includes ( item . id ) )
136+ ) ;
137+
138+ const orderedSections = displayedSections ( state ) ;
139+
140+ const moveSection = ( sectionId : string , direction : - 1 | 1 ) => {
131141 setState ( ( current ) => {
142+ // Swap with the DISPLAYED neighbor: a hidden Favorites entry may still sit in
143+ // sectionOrder between two visible sections
144+ const displayed = displayedSections ( current ) . map ( ( section ) => section . id ) ;
145+ const neighborId = displayed [ displayed . indexOf ( sectionId ) + direction ] ;
146+ if ( ! neighborId ) return current ;
132147 const next = [ ...current . sectionOrder ] ;
133- const target = index + direction ;
134- if ( target < 0 || target > = next . length ) return current ;
135- [ next [ index ] , next [ target ] ] = [ next [ target ] , next [ index ] ] ;
148+ const a = next . indexOf ( sectionId ) ;
149+ const b = next . indexOf ( neighborId ) ;
150+ [ next [ a ] , next [ b ] ] = [ next [ b ] , next [ a ] ] ;
136151 return { ...current , sectionOrder : next } ;
137152 } ) ;
138153 } ;
@@ -247,14 +262,14 @@ export function CustomizeSidebarDialog({
247262 < SectionMoveButton
248263 label = { `Move ${ section . title } up` }
249264 disabled = { index === 0 }
250- onClick = { ( ) => moveSection ( index , - 1 ) }
265+ onClick = { ( ) => moveSection ( section . id , - 1 ) }
251266 >
252267 < ArrowUpIcon className = "size-3.5" />
253268 </ SectionMoveButton >
254269 < SectionMoveButton
255270 label = { `Move ${ section . title } down` }
256271 disabled = { index === orderedSections . length - 1 }
257- onClick = { ( ) => moveSection ( index , 1 ) }
272+ onClick = { ( ) => moveSection ( section . id , 1 ) }
258273 >
259274 < ArrowDownIcon className = "size-3.5" />
260275 </ SectionMoveButton >
0 commit comments