Skip to content

Commit f30922e

Browse files
authored
[CLNP-6276] Formatted text paste bug-fix (#1307)
[fix]: Formatted text paste broken When a formatted text is copied and pasted into the `MessageInput`, the sanitized text is pasted instead of the text Fixes [CLNP-6276](https://sendbird.atlassian.net/browse/CLNP-6276) ### Changelogs - Fixed a bug that a formatted text is broken when pasted into the `MessageInput` ### Checklist Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If unsure, ask the members. This is a reminder of what we look for before merging your code. - [x] **All tests pass locally with my changes** - [ ] **I have added tests that prove my fix is effective or that my feature works** - [ ] **Public components / utils / props are appropriately exported** - [ ] I have added necessary documentation (if appropriate) ## External Contributions This project is not yet set up to accept pull requests from external contributors. If you have a pull request that you believe should be accepted, please contact the Developer Relations team <[email protected]> with details and we'll evaluate if we can set up a [CLA](https://en.wikipedia.org/wiki/Contributor_License_Agreement) to allow for the contribution. [CLNP-6276]: https://sendbird.atlassian.net/browse/CLNP-6276?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 3b5180f commit f30922e

File tree

1 file changed

+2
-3
lines changed
  • src/ui/MessageInput/hooks/usePaste

1 file changed

+2
-3
lines changed

src/ui/MessageInput/hooks/usePaste/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import DOMPurify from 'dompurify';
44
import { insertTemplateToDOM } from './insertTemplate';
55
import { sanitizeString } from '../../utils';
66
import { DynamicProps } from './types';
7-
import { domToMessageTemplate, extractTextFromNodes, getLeafNodes, getUsersFromWords, hasMention } from './utils';
7+
import { domToMessageTemplate, getLeafNodes, getUsersFromWords, hasMention } from './utils';
88

99
function pasteContentAtCaret(content: string) {
1010
const selection = window.getSelection(); // Get the current selection
@@ -60,8 +60,7 @@ export function usePaste({
6060

6161
if (!hasMention(pasteNode)) {
6262
// No mention, paste as plain text
63-
const extractedText = extractTextFromNodes(Array.from(pasteNode.children) as HTMLSpanElement[]);
64-
pasteContentAtCaret(sanitizeString(extractedText));
63+
pasteContentAtCaret(sanitizeString(text));
6564
pasteNode.remove();
6665
setIsInput(true);
6766
return;

0 commit comments

Comments
 (0)