From ffa12d93c7efc516ead1dfc798f9afc0d3ec1aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 19 Sep 2014 12:53:18 +0200 Subject: Windows style newlines are actually \r\n not \n\r This is fiddely stuff, hopefully it doesn't break too much --- window.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index a3b28b6..dc3e7dd 100644 --- a/window.c +++ b/window.c @@ -430,9 +430,10 @@ void window_draw(Win *win) { c.len = len; } - if (cur[0] == '\n' && rem > 1 && cur[1] == '\r') { - /* convert windows style newline \n\r into a single char with len = 2 */ - c.len = len = 2; + if (cur[0] == '\r' && rem > 1 && cur[1] == '\n') { + /* convert windows style newline \r\n into a single char with len = 2 */ + len = 2; + c = (Char){ .c = "\n", .wchar = L'\n', .len = len }; } wattrset(win->win, attrs); @@ -607,16 +608,18 @@ static bool window_viewport_up(Win *win, int n) { return false; size_t off = 0; /* skip newlines immediately before display area */ - if (c == '\r' && text_iterator_byte_prev(&it, &c)) - off++; if (c == '\n' && text_iterator_byte_prev(&it, &c)) off++; + if (c == '\r' && text_iterator_byte_prev(&it, &c)) + off++; do { - if ((c == '\n' || c == '\r') && --n == 0) + if (c == '\n' && --n == 0) break; if (++off > max) break; } while (text_iterator_byte_prev(&it, &c)); + if (c == '\r') + off++; win->start -= off; window_draw(win); return true; -- cgit v1.2.3