From 90485aaa2195062fc99f7eea65fad41f90026bb4 Mon Sep 17 00:00:00 2001 From: mere-human <9664141+mere-human@users.noreply.github.com> Date: Mon, 2 Aug 2021 22:13:53 +0300 Subject: [PATCH] Use CRLF line ending in Copy command from Windows dialog Also, move endsWith() function to Common.h and reuse it in WindowsDlg. Fix #10311, close #10314 --- PowerEditor/src/MISC/Common/Common.cpp | 9 +++++++++ PowerEditor/src/MISC/Common/Common.h | 1 + .../WinControls/OpenSaveFileDialog/CustomFileDialog.cpp | 9 --------- PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp | 6 +++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index 2c46bd7d7..c99c7553e 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -1297,6 +1297,15 @@ void trim(generic_string& str) else str.erase(str.begin(), str.end()); } +bool endsWith(const generic_string& s, const generic_string& suffix) +{ +#if defined(_MSVC_LANG) && (_MSVC_LANG > 201402L) +#error Replace this function with basic_string::ends_with +#endif + size_t pos = s.find(suffix); + return pos != s.npos && ((s.length() - pos) == suffix.length()); +} + int nbDigitsFromNbLines(size_t nbLines) { int nbDigits = 0; // minimum number of digit should be 4 diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index 1bcf8a3dd..c5cff1729 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -225,5 +225,6 @@ template size_t vecRemoveDuplicates(std::vector& vec, bool isSort } void trim(generic_string& str); +bool endsWith(const generic_string& s, const generic_string& suffix); int nbDigitsFromNbLines(size_t nbLines); diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp b/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp index 5ea3ae83f..5d080eef1 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp @@ -90,15 +90,6 @@ namespace // anonymous return name.find_last_of('.') != generic_string::npos; } - bool endsWith(const generic_string& s, const generic_string& suffix) - { -#if defined(_MSVC_LANG) && (_MSVC_LANG > 201402L) - #error Replace this function with basic_string::ends_with -#endif - size_t pos = s.find(suffix); - return pos != s.npos && ((s.length() - pos) == suffix.length()); - } - void expandEnv(generic_string& s) { TCHAR buffer[MAX_PATH] = { 0 }; diff --git a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp index 4abd7b648..a9492255c 100644 --- a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp +++ b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp @@ -984,6 +984,7 @@ void WindowsDlg::putItemsToClipboard(bool isFullPath) constexpr int pathColumn = 1; TCHAR str[MAX_PATH] = {}; + const generic_string crlf = _T("\r\n"); generic_string selection; for (int i = -1, j = 0; ; ++j) @@ -1008,9 +1009,8 @@ void WindowsDlg::putItemsToClipboard(bool isFullPath) if (fileName) selection += fileName; } - - if (!selection.empty() && selection.back() != '\n') - selection += '\n'; + if (!selection.empty() && !endsWith(selection, crlf)) + selection += crlf; } if (!selection.empty()) str2Clipboard(selection, _hList);