diff options
author | RadAd <adamgates84+github@gmail.com> | 2019-05-24 16:26:06 +1000 |
---|---|---|
committer | RadAd <adamgates84+github@gmail.com> | 2019-05-24 16:26:06 +1000 |
commit | e98699564b8dc81f7fe3d98446e1e967b9f2cb70 (patch) | |
tree | ee755101c8a94b9c32cdc97bbb8c29536752df79 | |
parent | fb5585bfe27b1288ca1df6b4fa01e9a39cf92077 (diff) | |
download | RadTerminal-e98699564b8dc81f7fe3d98446e1e967b9f2cb70.tar.gz RadTerminal-e98699564b8dc81f7fe3d98446e1e967b9f2cb70.zip |
Trim space from the end of lines when copying to clipboard
-rw-r--r-- | RadTerminal.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/RadTerminal.cpp b/RadTerminal.cpp index 1d5e812..7d91526 100644 --- a/RadTerminal.cpp +++ b/RadTerminal.cpp @@ -686,8 +686,40 @@ void RadTerminalWindowOnRButtonDown(HWND hWnd, BOOL fDoubleClick, int x, int y, int len = tsm_screen_selection_copy(data->screen, &buf); if (len > 0) { - HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len); - memcpy(GlobalLock(hMem), buf, len); + { // trim empty space from end of lines + char* lastnonnull = nullptr; + for (int i = 0; i < len; ++i) + { + switch (buf[i]) + { + case ' ': + case '\0': + //buf[i] = ' '; + break; + + case '\n': + if (lastnonnull != nullptr) + { + strncpy_s(lastnonnull, len - (lastnonnull - buf), buf + i, len - i); // TODO len should be len - (lastnonnull - buf) I think + int cut = (int) ((buf + i) - lastnonnull); + len -= cut; + i -= cut; + } + // fallthrough + + default: + lastnonnull = buf + i + 1; + break; + } + } + + *lastnonnull = '\0'; + int cut = (int) ((buf + len) - lastnonnull); + len -= cut; + } + + HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len + 1); + memcpy(GlobalLock(hMem), buf, len + 1); GlobalUnlock(hMem); while (!OpenClipboard(hWnd)) ; |