import { Strings } from "roosterjs-react-common" ; import Emoji from "../schema/Emoji" ; import { forEachEmoji } from "./emojiList" ; export function searchEmojis ( search , strings ) { const shortcutMatch = matchShortcut ( search ) ; search = search . toLowerCase ( ) ; const fullMatch = shortcutMatch ? [ shortcutMatch ] : [ ] ; const partialMatch = [ ] ; const partialSearch = " " + ( search [ 0 ] == ":" ? search . substr ( 1 ) : search ) ; forEachEmoji ( emoji => { const keywords = strings [ emoji . keywords ] || "" ; const searchableKeywords = emoji . keywords ? " " + keywords . toLowerCase ( ) + " " : "" ; const index = searchableKeywords . indexOf ( partialSearch ) ; if ( index >= 0 ) { ( searchableKeywords [ index + partialSearch . length ] == " " ? fullMatch : partialMatch ) . push ( emoji ) ; } return true ; } ) ; return fullMatch . concat ( partialMatch ) ; } export function matchShortcut ( search ) { let result ; search = " " + search + " " ; forEachEmoji ( ( emoji ) => { if ( emoji . shortcut && ( " " + emoji . shortcut + " " ) . indexOf ( search ) >= 0 ) { result = emoji ; return false ; } return true ; } ) ; return result ; }