Apply prettier formatting
This commit is contained in:
parent
1cac306093
commit
526645c791
1576 changed files with 65385 additions and 62478 deletions
|
@ -18,26 +18,26 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { uniq, sortBy } from 'lodash';
|
||||
import EMOTICON_REGEX from 'emojibase-regex/emoticon';
|
||||
import { Room } from 'matrix-js-sdk/src/models/room';
|
||||
import React from "react";
|
||||
import { uniq, sortBy } from "lodash";
|
||||
import EMOTICON_REGEX from "emojibase-regex/emoticon";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
|
||||
import { _t } from '../languageHandler';
|
||||
import AutocompleteProvider from './AutocompleteProvider';
|
||||
import QueryMatcher from './QueryMatcher';
|
||||
import { PillCompletion } from './Components';
|
||||
import { ICompletion, ISelectionRange } from './Autocompleter';
|
||||
import { _t } from "../languageHandler";
|
||||
import AutocompleteProvider from "./AutocompleteProvider";
|
||||
import QueryMatcher from "./QueryMatcher";
|
||||
import { PillCompletion } from "./Components";
|
||||
import { ICompletion, ISelectionRange } from "./Autocompleter";
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
import { EMOJI, IEmoji, getEmojiFromUnicode } from '../emoji';
|
||||
import { TimelineRenderingType } from '../contexts/RoomContext';
|
||||
import * as recent from '../emojipicker/recent';
|
||||
import { EMOJI, IEmoji, getEmojiFromUnicode } from "../emoji";
|
||||
import { TimelineRenderingType } from "../contexts/RoomContext";
|
||||
import * as recent from "../emojipicker/recent";
|
||||
|
||||
const LIMIT = 20;
|
||||
|
||||
// Match for ascii-style ";-)" emoticons or ":wink:" shortcodes provided by emojibase
|
||||
// anchored to only match from the start of parts otherwise it'll show emoji suggestions whilst typing matrix IDs
|
||||
const EMOJI_REGEX = new RegExp('(' + EMOTICON_REGEX.source + '|(?:^|\\s):[+-\\w]*:?)$', 'g');
|
||||
const EMOJI_REGEX = new RegExp("(" + EMOTICON_REGEX.source + "|(?:^|\\s):[+-\\w]*:?)$", "g");
|
||||
|
||||
interface ISortedEmoji {
|
||||
emoji: IEmoji;
|
||||
|
@ -80,12 +80,12 @@ export default class EmojiProvider extends AutocompleteProvider {
|
|||
super({ commandRegex: EMOJI_REGEX, renderingType });
|
||||
this.matcher = new QueryMatcher<ISortedEmoji>(SORTED_EMOJI, {
|
||||
keys: [],
|
||||
funcs: [o => o.emoji.shortcodes.map(s => `:${s}:`)],
|
||||
funcs: [(o) => o.emoji.shortcodes.map((s) => `:${s}:`)],
|
||||
// For matching against ascii equivalents
|
||||
shouldMatchWordsOnly: false,
|
||||
});
|
||||
this.nameMatcher = new QueryMatcher(SORTED_EMOJI, {
|
||||
keys: ['emoji.label'],
|
||||
keys: ["emoji.label"],
|
||||
// For removing punctuation
|
||||
shouldMatchWordsOnly: true,
|
||||
});
|
||||
|
@ -115,39 +115,37 @@ export default class EmojiProvider extends AutocompleteProvider {
|
|||
|
||||
let sorters = [];
|
||||
// make sure that emoticons come first
|
||||
sorters.push(c => score(matchedString, c.emoji.emoticon || ""));
|
||||
sorters.push((c) => score(matchedString, c.emoji.emoticon || ""));
|
||||
|
||||
// then sort by score (Infinity if matchedString not in shortcode)
|
||||
sorters.push(c => score(matchedString, c.emoji.shortcodes[0]));
|
||||
sorters.push((c) => score(matchedString, c.emoji.shortcodes[0]));
|
||||
// then sort by max score of all shortcodes, trim off the `:`
|
||||
const trimmedMatch = colonsTrimmed(matchedString);
|
||||
sorters.push(c => Math.min(
|
||||
...c.emoji.shortcodes.map(s => score(trimmedMatch, s)),
|
||||
));
|
||||
sorters.push((c) => Math.min(...c.emoji.shortcodes.map((s) => score(trimmedMatch, s))));
|
||||
// If the matchedString is not empty, sort by length of shortcode. Example:
|
||||
// matchedString = ":bookmark"
|
||||
// completions = [":bookmark:", ":bookmark_tabs:", ...]
|
||||
if (matchedString.length > 1) {
|
||||
sorters.push(c => c.emoji.shortcodes[0].length);
|
||||
sorters.push((c) => c.emoji.shortcodes[0].length);
|
||||
}
|
||||
// Finally, sort by original ordering
|
||||
sorters.push(c => c._orderBy);
|
||||
sorters.push((c) => c._orderBy);
|
||||
completions = sortBy<ISortedEmoji>(uniq(completions), sorters);
|
||||
|
||||
completions = completions.slice(0, LIMIT);
|
||||
|
||||
// Do a second sort to place emoji matching with frequently used one on top
|
||||
sorters = [];
|
||||
this.recentlyUsed.forEach(emoji => {
|
||||
sorters.push(c => score(emoji.shortcodes[0], c.emoji.shortcodes[0]));
|
||||
this.recentlyUsed.forEach((emoji) => {
|
||||
sorters.push((c) => score(emoji.shortcodes[0], c.emoji.shortcodes[0]));
|
||||
});
|
||||
completions = sortBy<ISortedEmoji>(uniq(completions), sorters);
|
||||
|
||||
return completions.map(c => ({
|
||||
return completions.map((c) => ({
|
||||
completion: c.emoji.unicode,
|
||||
component: (
|
||||
<PillCompletion title={`:${c.emoji.shortcodes[0]}:`} aria-label={c.emoji.unicode}>
|
||||
<span>{ c.emoji.unicode }</span>
|
||||
<span>{c.emoji.unicode}</span>
|
||||
</PillCompletion>
|
||||
),
|
||||
range,
|
||||
|
@ -157,7 +155,7 @@ export default class EmojiProvider extends AutocompleteProvider {
|
|||
}
|
||||
|
||||
getName() {
|
||||
return '😃 ' + _t('Emoji');
|
||||
return "😃 " + _t("Emoji");
|
||||
}
|
||||
|
||||
renderCompletions(completions: React.ReactNode[]): React.ReactNode {
|
||||
|
@ -167,7 +165,7 @@ export default class EmojiProvider extends AutocompleteProvider {
|
|||
role="presentation"
|
||||
aria-label={_t("Emoji Autocomplete")}
|
||||
>
|
||||
{ completions }
|
||||
{completions}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue