@@ -59,6 +59,11 @@ GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
59
59
Console -> Selection .srSelection .Right ,
60
60
Console -> Selection .srSelection .Bottom );
61
61
62
+ #ifdef IS_WHITESPACE
63
+ #undef IS_WHITESPACE
64
+ #endif
65
+ #define IS_WHITESPACE (c ) ((c) == L'\0' || (c) == L' ' || (c) == L'\t')
66
+
62
67
/* Basic size for one line... */
63
68
size = selWidth ;
64
69
/* ... and for the other lines, add newline characters if needed. */
@@ -89,23 +94,31 @@ GuiCopyFromTextModeBuffer(PTEXTMODE_SCREEN_BUFFER Buffer,
89
94
90
95
for (yPos = 0 ; yPos < selHeight ; yPos ++ )
91
96
{
97
+ ULONG length = selWidth ;
98
+
92
99
ptr = ConioCoordToPointer (Buffer ,
93
100
Console -> Selection .srSelection .Left ,
94
101
Console -> Selection .srSelection .Top + yPos );
102
+
103
+ /* Trim whitespace from the right */
104
+ while (length > 0 )
105
+ {
106
+ if (IS_WHITESPACE (ptr [length - 1 ].Char .UnicodeChar ))
107
+ -- length ;
108
+ else
109
+ break ;
110
+ }
111
+
95
112
/* Copy only the characters, leave attributes alone */
96
- for (xPos = 0 ; xPos < selWidth ; xPos ++ )
113
+ for (xPos = 0 ; xPos < length ; xPos ++ )
97
114
{
98
115
/*
99
116
* Sometimes, applications can put NULL chars into the screen-buffer
100
117
* (this behaviour is allowed). Detect this and replace by a space.
101
- * FIXME - HACK: Improve the way we're doing that (i.e., put spaces
102
- * instead of NULLs (or even, nothing) only if it exists a non-null
103
- * char *after* those NULLs, before the end-of-line of the selection.
104
- * Do the same concerning spaces -- i.e. trailing spaces --).
105
118
*/
106
119
dstPos [xPos ] = (ptr [xPos ].Char .UnicodeChar ? ptr [xPos ].Char .UnicodeChar : L' ' );
107
120
}
108
- dstPos += selWidth ;
121
+ dstPos += length ;
109
122
110
123
/* Add newline characters if we are not in inline-text copy mode */
111
124
if (!InlineCopyMode )
0 commit comments