1+ import { VIRTUALIZE_CLASS_NAMES } from '../components/Layout/Virtualise' ;
12import { DataEmoji } from '../dataUtils/DataTypes' ;
23import {
34 emojiByUnified ,
@@ -267,7 +268,37 @@ export function firstVisibleEmoji(parent: NullableElement) {
267268 return firstVisibleElementInContainer ( parent , allEmojis , 0.1 ) ;
268269}
269270
271+
272+ const getNameBasedPrevCategory = ( element : HTMLElement ) : HTMLElement | null => {
273+ const emojiList = document . querySelector < HTMLElement > ( asSelectors ( ClassNames . emojiList ) ) ;
274+ if ( ! emojiList ) return null ;
275+
276+ const currentName = element ?. getAttribute ( 'data-name' ) ;
277+ const categories = Array . from ( emojiList . children ) ;
278+ const currentIndex = categories . findIndex (
279+ child => child . firstElementChild ?. getAttribute ( 'data-name' ) === currentName
280+ ) ;
281+
282+ const prevIndex = Math . max ( currentIndex - 1 , 0 ) ;
283+ const prevName = categories [ prevIndex ] ?. firstElementChild ?. getAttribute ( 'data-name' ) ;
284+
285+ return prevName
286+ ? emojiList . querySelector ( `[data-name="${ prevName } "]` ) as HTMLElement
287+ : null ;
288+ } ;
289+
290+
270291export function prevCategory ( element : NullableElement ) : NullableElement {
292+ if ( ! element ) {
293+ return null ;
294+ }
295+
296+ const currentPrevCategory = getNameBasedPrevCategory ( element ) ;
297+
298+ if ( currentPrevCategory ) {
299+ return currentPrevCategory ;
300+ }
301+
271302 const category = closestCategory ( element ) ;
272303
273304 if ( ! category ) {
@@ -287,7 +318,36 @@ export function prevCategory(element: NullableElement): NullableElement {
287318 return prev ;
288319}
289320
321+ const getNameBasedNextCategory = ( element : HTMLElement ) : HTMLElement | null => {
322+ const emojiList = document . querySelector < HTMLElement > ( asSelectors ( ClassNames . emojiList ) ) ;
323+ if ( ! emojiList ) return null ;
324+
325+ const currentName = element ?. getAttribute ( 'data-name' ) ;
326+ const categories = Array . from ( emojiList . children ) ;
327+ const currentIndex = categories . findIndex (
328+ child => child . firstElementChild ?. getAttribute ( 'data-name' ) === currentName
329+ ) ;
330+
331+ const nextIndex = Math . min ( currentIndex + 1 , categories . length - 1 ) ;
332+ const nextName = categories [ nextIndex ] ?. firstElementChild ?. getAttribute ( 'data-name' ) ;
333+
334+ return nextName
335+ ? emojiList . querySelector ( `[data-name="${ nextName } "]` )
336+ : null ;
337+ } ;
338+
339+
290340export function nextCategory ( element : NullableElement ) : NullableElement {
341+ if ( ! element ) {
342+ return null ;
343+ }
344+
345+ const currentNextCategory = getNameBasedNextCategory ( element ) ;
346+
347+ if ( currentNextCategory ) {
348+ return currentNextCategory ;
349+ }
350+
291351 const category = closestCategory ( element ) ;
292352
293353 if ( ! category ) {
0 commit comments