From 5a5acefe3bf589f972d7ab09b4e44fe49a8cabb9 Mon Sep 17 00:00:00 2001 From: zombiej Date: Wed, 27 Jan 2021 17:19:53 +0800 Subject: [PATCH 1/2] fix: br logic --- src/Selector/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Selector/index.tsx b/src/Selector/index.tsx index a9c581219..9078b5555 100644 --- a/src/Selector/index.tsx +++ b/src/Selector/index.tsx @@ -185,7 +185,10 @@ const Selector: React.RefForwardingComponent = // Pasted text should replace back to origin content if (tokenWithEnter && pastedTextRef.current && /[\r\n]/.test(pastedTextRef.current)) { // CRLF will be treated as a single space for input element - const replacedText = pastedTextRef.current.replace(/\r\n/g, ' ').replace(/[\r\n]/g, ' '); + const replacedText = pastedTextRef.current + .replace(/[\r\n]+$/, '') + .replace(/\r\n/g, ' ') + .replace(/[\r\n]/g, ' '); value = value.replace(replacedText, pastedTextRef.current); } From 17073e1283c3bdf3a63c2818aa761b7e7a235ebf Mon Sep 17 00:00:00 2001 From: zombiej Date: Wed, 27 Jan 2021 17:22:28 +0800 Subject: [PATCH 2/2] fix: Test case --- tests/Tags.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Tags.test.tsx b/tests/Tags.test.tsx index e443c77a6..80a1b8933 100644 --- a/tests/Tags.test.tsx +++ b/tests/Tags.test.tsx @@ -154,7 +154,7 @@ describe('Select.Tags', () => { { tokenSeparators: ['\r\n'], clipboardText: '\r\nlight\r\nbamboo\r\n', - inputValue: ' light bamboo ', + inputValue: ' light bamboo', }, { tokenSeparators: [' ', '\r\n'], @@ -164,7 +164,7 @@ describe('Select.Tags', () => { { tokenSeparators: ['\n'], clipboardText: '\nlight\nbamboo\n', - inputValue: ' light bamboo ', + inputValue: ' light bamboo', }, ].forEach(({ tokenSeparators, clipboardText, inputValue }) => { it(`paste content to split (${JSON.stringify(tokenSeparators)})`, () => {