Skip to content

Commit

Permalink
Fix \r's being added to end of lines when pasting text on Windows
Browse files Browse the repository at this point in the history
This also broke copy-pasting of textboxes that overflowed the 8 line limit
with the extra characters

git-svn-id: https://rpg.hamsterrepublic.com/source/wip@11582 7d344553-34f0-0310-a9b1-970ce8f1c3a2
  • Loading branch information
rversteegen committed Feb 3, 2020
1 parent c0376ec commit 0a58971
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions common.rbas
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,12 @@ SUB handle_text_copy_paste (byref text as string, byref clip as string)
IF paste_keychord() THEN
DIM osclip as zstring ptr 'ustring
osclip = io_get_clipboard_text()
#IFDEF __FB_WIN32__
'On Windows text in the clipboard uses \r\n line ends, so
'io_set_clipboard_text() converts to that, but io_get_clipboard_text()
'doesn't automatically convert back.
strip_carriage_returns osclip 'Modify in-place
#ENDIF
'Intentionally using utf8_to_latin1 instead of utf8_to_ohr here, so that
'round trips of text from OHR -> clipboard/other programs -> OHR don't lose
'icon characters.
Expand Down
2 changes: 2 additions & 0 deletions cutil.bi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ declare function get_sys_err_string() as zstring ptr

declare function stringhash(byval strp as zstring ptr, byval leng as integer) as unsigned integer

declare sub strip_carriage_returns(byval text as zstring ptr)

declare function strprintf (byval fmtstr as zstring ptr, ...) as string

declare sub init_crt ()
Expand Down
4 changes: 4 additions & 0 deletions lib/SDL/SDL_windowsclipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ WIN_GetClipboardText(HWND hWindow)
}
}
CloseClipboard();

// WIN_SetClipboardText converts to \r\n; convert back
//if (text)
// strip_carriage_returns(text);
}
if (!text) {
text = strdup("");
Expand Down
2 changes: 2 additions & 0 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ FBSTRING *return_fbstring(FBSTRING *fbstr);
FBSTRING *empty_fbstring();
void delete_fbstring(FBSTRING *str);

void strip_carriage_returns(char *text);

uint32_t stringhash(const unsigned char *strp, int length);

void disable_extended_precision();
Expand Down
18 changes: 18 additions & 0 deletions miscc.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ FBSTRING *strprintf (const char *fmtstr, ...) {
}


////////////////////////////// String funcs ///////////////////////////////////


// Strip out the carriage return (\r) chars in a string in-place.
void strip_carriage_returns(char *text) {
char *src = text, *dst = text;
for (; *src; ++src) {
if (*src == '\r') {
if (src[1] == '\n')
continue; // Skip over the \r
*dst++ = '\n'; // If a lone \r occurs, convert to \n
} else
*dst++ = *src;
}
*dst = '\0';
}


///////////////////////////////// Hashing /////////////////////////////////////


Expand Down
2 changes: 2 additions & 0 deletions whatsnew.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ April ? 2020 [Gorgonzola]
*** Bugfixes
* Linux builds should now hopefully work on all Linux systems since 2011
(as long as SDL & SDL_mixer are installed) [Ralph]
* On Windows, copy-pasting text caused spaces to be added at line ends,
and near-full textboxes couldn't be copy-pasted [Ralph]

*** Stuff Only Developers Will Notice

Expand Down

0 comments on commit 0a58971

Please sign in to comment.