add emoji autocomplete threshold setting
This commit is contained in:
4 files changed
+69
-3
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
sable: minor
|
||||
---
|
||||
|
||||
Added a new setting "Emoji Selector Character Threshold" to set the number of characters to type before the suggestions pop up.
|
||||
@@ -14,6 +14,8 @@ import { mxcUrlToHttp } from '$utils/matrix';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { ImageUsage, PackImageReader } from '$plugins/custom-emoji';
|
||||
import { getEmoticonSearchStr } from '$plugins/utils';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { createEmoticonElement, moveCursor, replaceWithElement } from '$components/editor/utils';
|
||||
import { AutocompleteMenu } from './AutocompleteMenu';
|
||||
import { AutocompleteQuery } from './autocompleteQuery';
|
||||
@@ -53,6 +55,8 @@ export function EmoticonAutocomplete({
|
||||
const imagePacks = useRelevantImagePacks(ImageUsage.Emoticon, imagePackRooms);
|
||||
const recentEmoji = useRecentEmoji(mx, 20);
|
||||
|
||||
const [emojiThreshold] = useSetting(settingsAtom, 'emojiSuggestThreshold');
|
||||
|
||||
const searchList = useMemo(() => {
|
||||
const list: Array<EmoticonSearchItem> = [];
|
||||
return list.concat(
|
||||
@@ -69,9 +73,12 @@ export function EmoticonAutocomplete({
|
||||
const autoCompleteEmoticon = result ? result.items.slice(0, 20) : recentEmoji;
|
||||
|
||||
useEffect(() => {
|
||||
if (query.text) search(query.text);
|
||||
else resetSearch();
|
||||
}, [query.text, search, resetSearch]);
|
||||
if (query.text && query.text.length >= emojiThreshold) {
|
||||
search(query.text);
|
||||
} else {
|
||||
resetSearch();
|
||||
}
|
||||
}, [query.text, search, resetSearch, emojiThreshold]);
|
||||
|
||||
const handleAutocomplete: EmoticonCompleteHandler =
|
||||
onEmoticonSelected ??
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
ChangeEventHandler,
|
||||
FormEventHandler,
|
||||
KeyboardEventHandler,
|
||||
MouseEventHandler,
|
||||
useEffect,
|
||||
useState,
|
||||
@@ -22,6 +23,7 @@ import {
|
||||
Scroll,
|
||||
Switch,
|
||||
Text,
|
||||
toRem,
|
||||
} from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
@@ -46,6 +48,7 @@ import { SequenceCardStyle } from '$features/settings/styles.css';
|
||||
import { sessionsAtom, activeSessionIdAtom } from '$state/sessions';
|
||||
import { useClientConfig } from '$hooks/useClientConfig';
|
||||
import { resolveSlidingEnabled } from '$client/initMatrix';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
|
||||
type DateHintProps = {
|
||||
hasChanges: boolean;
|
||||
@@ -689,6 +692,49 @@ function Gestures({ isMobile }: { isMobile: boolean }) {
|
||||
);
|
||||
}
|
||||
|
||||
function EmojiSelectorThresholdInput() {
|
||||
const [emojiThreshold, setEmojiThreshold] = useSetting(settingsAtom, 'emojiSuggestThreshold');
|
||||
const [inputValue, setInputValue] = useState(emojiThreshold.toString());
|
||||
|
||||
const handleChange: ChangeEventHandler<HTMLInputElement> = (evt) => {
|
||||
const val = evt.target.value;
|
||||
setInputValue(val);
|
||||
|
||||
const parsed = parseInt(val, 10);
|
||||
if (!Number.isNaN(parsed) && parsed >= 1 && parsed <= 10) {
|
||||
setEmojiThreshold(parsed);
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown: KeyboardEventHandler<HTMLInputElement> = (evt) => {
|
||||
if (isKeyHotkey('escape', evt)) {
|
||||
evt.stopPropagation();
|
||||
setInputValue(emojiThreshold.toString());
|
||||
(evt.target as HTMLInputElement).blur();
|
||||
}
|
||||
|
||||
if (isKeyHotkey('enter', evt)) {
|
||||
(evt.target as HTMLInputElement).blur();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Input
|
||||
style={{ width: toRem(80) }}
|
||||
variant={parseInt(inputValue, 10) === emojiThreshold ? 'Secondary' : 'Success'}
|
||||
size="300"
|
||||
radii="300"
|
||||
type="number"
|
||||
min="1"
|
||||
max="10"
|
||||
value={inputValue}
|
||||
onChange={handleChange}
|
||||
onKeyDown={handleKeyDown}
|
||||
outlined
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function Messages() {
|
||||
const [hideMembershipEvents, setHideMembershipEvents] = useSetting(
|
||||
settingsAtom,
|
||||
@@ -716,6 +762,12 @@ function Messages() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile title="Message Spacing" after={<SelectMessageSpacing />} />
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Emoji Selector Character Threshold"
|
||||
after={<EmojiSelectorThresholdInput />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Hide Membership Change"
|
||||
|
||||
@@ -79,6 +79,7 @@ export interface Settings {
|
||||
badgeCountDMsOnly: boolean;
|
||||
showPingCounts: boolean;
|
||||
hideReads: boolean;
|
||||
emojiSuggestThreshold: number;
|
||||
}
|
||||
|
||||
const defaultSettings: Settings = {
|
||||
@@ -144,6 +145,7 @@ const defaultSettings: Settings = {
|
||||
badgeCountDMsOnly: false,
|
||||
showPingCounts: true,
|
||||
hideReads: false,
|
||||
emojiSuggestThreshold: 2,
|
||||
};
|
||||
|
||||
export const getSettings = () => {
|
||||
|
||||
Reference in new issue
Block a user