From: Holger Schemel Date: Mon, 25 Feb 2019 20:40:52 +0000 (+0100) Subject: fixed level sketch copy/paste via clipboard on Windows (using CR+LF) X-Git-Tag: 4.1.3.0~54 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=fe21ed78a5927518daeb7307488415416ef98b6a;p=rocksndiamonds.git fixed level sketch copy/paste via clipboard on Windows (using CR+LF) Before, level sketch copy/paste using Ctrl-c/v in level editor did not work on Windows, where lines of text in the clipboard are terminated with CR+LF (carriage return and line feed) instead of simple newlines. This fixes this bug, and makes parsing level sketches from clipboard a little bit more robust regarding empty lines and garbage text. --- diff --git a/src/editor.c b/src/editor.c index dc1b528f..5eed0066 100644 --- a/src/editor.c +++ b/src/editor.c @@ -12063,11 +12063,13 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, char *clipboard_text = SDL_GetClipboardText(); char *ptr = clipboard_text; + boolean allow_new_row = FALSE; boolean stop = FALSE; while (*ptr && !stop) { boolean prefix_found = FALSE; + boolean start_new_row = FALSE; // level sketch element number prefixes (may be multi-byte characters) char *prefix_list[] = { "`", "¸" }; @@ -12096,19 +12098,10 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, } } - // continue with next character if prefix not found - if (!prefix_found) - { - ptr++; // !!! FIX THIS for real UTF-8 handling !!! - - continue; - } - - // continue with next character if prefix not found - if (strlen(ptr) < 3) - break; - - if (ptr[0] >= '0' && ptr[0] <= '9' && + // check if prefix found and followed by three numbers + if (prefix_found && + strlen(ptr) >= 3 && + ptr[0] >= '0' && ptr[0] <= '9' && ptr[1] >= '0' && ptr[1] <= '9' && ptr[2] >= '0' && ptr[2] <= '9') { @@ -12128,14 +12121,28 @@ static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, x++; - if (x >= MAX_LEV_FIELDX || *ptr == '\n') - { - x = 0; - y++; + if (x >= MAX_LEV_FIELDX) + start_new_row = TRUE; - if (y >= MAX_LEV_FIELDY) - stop = TRUE; - } + allow_new_row = TRUE; + } + else + { + if ((*ptr == '\n' || *ptr == '\r') && allow_new_row) + start_new_row = TRUE; + + ptr++; // !!! FIX THIS for real UTF-8 handling !!! + } + + if (start_new_row) + { + x = 0; + y++; + + if (y >= MAX_LEV_FIELDY) + stop = TRUE; + + allow_new_row = FALSE; } }