From 1567faca3ce212bc850d6647ba0fe4f4f06a2ef4 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Fri, 10 Feb 2023 09:56:45 +0100 Subject: [PATCH] Fix issues with newlines when copypasting --- src/components/Composer/index.js | 6 ++---- src/components/CopySelectionHelper.js | 4 +++- src/pages/home/report/ContextMenu/ContextMenuActions.js | 6 +----- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/components/Composer/index.js b/src/components/Composer/index.js index 5e00825c5a50..d94fea6c18b8 100755 --- a/src/components/Composer/index.js +++ b/src/components/Composer/index.js @@ -268,7 +268,7 @@ class Composer extends React.Component { return; } - const plainText = event.clipboardData.getData('text/plain').replace(/\n\n/g, '\n'); + const plainText = event.clipboardData.getData('text/plain'); this.paste(Str.htmlDecode(plainText)); } @@ -297,9 +297,7 @@ class Composer extends React.Component { // the only stuff put into the clipboard is what the user selected. const selectedText = event.target.value.substring(this.state.selection.start, this.state.selection.end); - // The plaintext portion that is put into the clipboard needs to have the newlines duplicated. This is because - // the paste functionality is stripping all duplicate newlines to try and provide consistent behavior. - Clipboard.setHtml(selectedText, selectedText.replace(/\n/g, '\n\n')); + Clipboard.setHtml(selectedText, selectedText); } /** diff --git a/src/components/CopySelectionHelper.js b/src/components/CopySelectionHelper.js index d7d5d206d2c1..f300adabcbff 100644 --- a/src/components/CopySelectionHelper.js +++ b/src/components/CopySelectionHelper.js @@ -36,7 +36,9 @@ class CopySelectionHelper extends React.Component { Clipboard.setString(parser.htmlToMarkdown(selection)); return; } - Clipboard.setHtml(selection, Str.htmlDecode(parser.htmlToText(selection))); + + // Replace doubled newlines with the single ones because selection from SelectionScraper html contains doubled
marks + Clipboard.setHtml(selection, Str.htmlDecode(parser.htmlToText(selection).replace(/\n\n/g, '\n'))); } render() { diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index a75e3963e715..949286358000 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -112,11 +112,7 @@ export default [ if (!Clipboard.canSetHtml()) { Clipboard.setString(parser.htmlToMarkdown(content)); } else { - // Thanks to how browsers work, when text is highlighted and CTRL+c is pressed, browsers end up doubling the amount of newlines. Since the code in this file is - // triggered from a context menu and not CTRL+c, the newlines need to be doubled so that the content that goes into the clipboard is consistent with CTRL+c behavior. - // The extra newlines are stripped when the contents are pasted into the compose input, but if the contents are pasted outside of the comment composer, it will - // contain extra newlines and that's OK because it is consistent with CTRL+c behavior. - const plainText = Str.htmlDecode(parser.htmlToText(content)).replace(/\n/g, '\n\n'); + const plainText = Str.htmlDecode(parser.htmlToText(content)); Clipboard.setHtml(content, plainText); } }