This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 811
Rich text Editor: Auto-replace plain text emoticons with emoji #12828
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8a5ae17
Detect autoReplaceEmoji setting
langleyd f01cb50
Merge branch 'develop' of https://github.com/matrix-org/matrix-react-…
langleyd b9cdfaa
Merge branch 'develop' of https://github.com/matrix-org/matrix-react-…
langleyd 8e08d5a
Add plain text emoticon to emoji replacement for plain and rich text …
langleyd a99a6b6
Use latest wysiwyg
langleyd cdfd5f2
lint
langleyd 54bd5e5
Merge branch 'develop' into langleyd/rte_auto_replace_emoji
langleyd d8b7a2a
fix existing jest tests and docs
langleyd 8375ddb
Merge branch 'langleyd/rte_auto_replace_emoji' of https://github.com/…
langleyd 714abb8
Merge branch 'develop' of https://github.com/matrix-org/matrix-react-…
langleyd c105b27
Add unit tests
langleyd ef59141
Update wysiwyg to fix flakes.
langleyd 1ec173c
Merge branch 'develop' into langleyd/rte_auto_replace_emoji
langleyd 89a1489
fix wording of tests and comments
langleyd 38dd56a
Merge branch 'develop' of https://github.com/matrix-org/matrix-react-…
langleyd 3e0134b
use useSettingValue
langleyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,9 @@ See the License for the specific language governing permissions and | |
| limitations under the License. | ||
| */ | ||
|
|
||
| import React, { memo, MutableRefObject, ReactNode, useEffect, useRef } from "react"; | ||
| import React, { memo, MutableRefObject, ReactNode, useEffect, useRef, useState } from "react"; | ||
| import { IEventRelation } from "matrix-js-sdk/src/matrix"; | ||
| import { EMOTICON_TO_EMOJI } from "@matrix-org/emojibase-bindings"; | ||
| import { useWysiwyg, FormattingFunctions } from "@matrix-org/matrix-wysiwyg"; | ||
| import classNames from "classnames"; | ||
|
|
||
|
|
@@ -31,6 +32,7 @@ import defaultDispatcher from "../../../../../dispatcher/dispatcher"; | |
| import { Action } from "../../../../../dispatcher/actions"; | ||
| import { parsePermalink } from "../../../../../utils/permalinks/Permalinks"; | ||
| import { isNotNull } from "../../../../../Typeguards"; | ||
| import SettingsStore from "../../../../../settings/SettingsStore"; | ||
|
|
||
| interface WysiwygComposerProps { | ||
| disabled?: boolean; | ||
|
|
@@ -45,6 +47,11 @@ interface WysiwygComposerProps { | |
| eventRelation?: IEventRelation; | ||
| } | ||
|
|
||
| function getEmojiSuggestions(enabled: boolean): Map<string, string> { | ||
| const emojiSuggestions = new Map(Array.from(EMOTICON_TO_EMOJI, ([key, value]) => [key, value.unicode])); | ||
| return enabled ? emojiSuggestions : new Map(); | ||
| } | ||
|
|
||
| export const WysiwygComposer = memo(function WysiwygComposer({ | ||
| disabled = false, | ||
| onChange, | ||
|
|
@@ -61,9 +68,26 @@ export const WysiwygComposer = memo(function WysiwygComposer({ | |
| const autocompleteRef = useRef<Autocomplete | null>(null); | ||
|
|
||
| const inputEventProcessor = useInputEventProcessor(onSend, autocompleteRef, initialContent, eventRelation); | ||
|
|
||
| const [emojiSuggestions, setEmojiSuggestions] = useState( | ||
| getEmojiSuggestions(SettingsStore.getValue<boolean>("MessageComposerInput.autoReplaceEmoji")), | ||
|
||
| ); | ||
|
|
||
| useEffect(() => { | ||
| const ref = SettingsStore.watchSetting("MessageComposerInput.autoReplaceEmoji", null, (...[, , , value]) => { | ||
| setEmojiSuggestions(getEmojiSuggestions(value as boolean)); | ||
| }); | ||
|
|
||
| // clean-up | ||
| return () => { | ||
| SettingsStore.unwatchSetting(ref); | ||
| }; | ||
| }); | ||
|
|
||
| const { ref, isWysiwygReady, content, actionStates, wysiwyg, suggestion, messageContent } = useWysiwyg({ | ||
| initialContent, | ||
| inputEventProcessor, | ||
| emojiSuggestions, | ||
| }); | ||
|
|
||
| const { isFocused, onFocus } = useIsFocused(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there's also
useSettingValueto do the getting + watching + unsubscribing for youThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I actually looked for something as such, obviously not hard enough. 😂 thanks Dave