but your code doesn't release the selection on button up, which is rather strange when you do only mouse selection A+
I've checked it and currently the whole section is dead code as on WM_LBUTTONUP the (wParam&MK_LBUTTON) is always false.
However if I remove this condition I think my code is correct. I release the mouse capture - that's enough as the handler for WM_MOUSEMOVE and WM_LBUTTONUP checks if GetCapture() == PRIVATE(data)->hWnd. Setting has_selection = FALSE would means that the seletion has been removed - there would be no way to copy it to the clipboard. Also the window is not updated to show that the selection is removed.
I'll check if the spaces are removed for other console modes. I don't know if it's possible to write an automatic test as this requires mouse interaction, I don't know how to get a hWnd of a console windows. Also it would fail on wine as by default it starts the ncurses backend.
Mikolaj Zalewski