From 43087e3fa33d27978b9c06b6a3dba8183628d4fd Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 17 Jul 2017 09:52:23 -0400 Subject: [PATCH] Fixed failing unit test --- inc/x11.h | 2 +- lib/buf.c | 2 +- lib/view.c | 2 +- lib/win.c | 11 ++++++----- tests/tide.c | 4 +--- tide.c | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/inc/x11.h b/inc/x11.h index 06a8a7e..a22224b 100644 --- a/inc/x11.h +++ b/inc/x11.h @@ -1,6 +1,6 @@ typedef struct { void (*redraw)(int width, int height); - void (*handle_key)(int mods, uint32_t rune); + void (*handle_key)(int mods, int32_t rune); void (*shutdown)(void); void (*set_focus)(bool focus); void (*mouse_drag)(int state, int x, int y); diff --git a/lib/buf.c b/lib/buf.c index fc81b52..af99ee9 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -551,7 +551,7 @@ static size_t insert(Buf* buf, size_t off, Rune rune) { size_t rcount = 1; syncgap(buf, off); if (off < buf->outpoint) buf->outpoint++; - if (rune == '\n') buf->nlines++; + if (rune == '\n' || rune == RUNE_CRLF) buf->nlines++; if (buf->crlf && rune == '\n' && buf_get(buf, off-1) == '\r') { rcount = 0; *(buf->gapstart-1) = RUNE_CRLF; diff --git a/lib/view.c b/lib/view.c index 90dbdbc..eee19b7 100644 --- a/lib/view.c +++ b/lib/view.c @@ -208,7 +208,7 @@ bool view_findstr(View* view, int dir, char* str) { void view_insert(View* view, bool indent, Rune rune) { /* ignore non-printable control characters */ - if (!isspace(rune) && rune < 0x20) + if (!isspace(rune) && (rune >= 0 && rune < 0x20)) return; if (num_selected(view->selection)) { Sel sel = view->selection; diff --git a/lib/win.c b/lib/win.c index 6f0c163..7b6275d 100644 --- a/lib/win.c +++ b/lib/win.c @@ -305,16 +305,17 @@ static void oninput(int mods, Rune key) { } } + /* translate to crlf if needed */ + if (key == '\n' && win_view(FOCUSED)->buffer.crlf) + key = RUNE_CRLF; + /* fallback to just inserting the rune if it doesn't fall in the private use area. * the private use area is used to encode special keys */ if (key < 0xE000 || key > 0xF8FF) { - if (InputFunc) { + if (InputFunc) InputFunc(key); - } else { - if (key == '\n' && win_view(FOCUSED)->buffer.crlf) - key = RUNE_CRLF; + else view_insert(win_view(FOCUSED), true, key); - } } } diff --git a/tests/tide.c b/tests/tide.c index 9885022..8af7b28 100644 --- a/tests/tide.c +++ b/tests/tide.c @@ -33,7 +33,6 @@ static void initialize(void) { #define EXPECT_EXIT \ if ((ExitExpected = true, 0 == setjmp(ExitPad))) - void setup_view(WinRegion id, char* text, int crlf, unsigned cursor) { win_setregion(id); win_buf(id)->crlf = crlf; @@ -82,7 +81,7 @@ TEST_SUITE(UnitTests) { CHECK(win_sel(EDIT)->end == 1); } - TEST(input \n chould result in RUNE_CRLF if in crlf mode) { + TEST(input \n should result in RUNE_CRLF if in crlf mode) { setup_view(EDIT, "", CRLF, 0); win_buf(EDIT)->crlf = 1; send_keys(ModNone, XK_Return); @@ -99,7 +98,6 @@ TEST_SUITE(UnitTests) { CHECK(win_sel(EDIT)->end == 1); CHECK('\n' == buf_get(win_buf(EDIT), 0)); } - /* Key Handling - Cursor Movement - Basic *************************************************************************/ TEST(left should do nothing for empty buffer) { diff --git a/tide.c b/tide.c index 3712d23..47466df 100644 --- a/tide.c +++ b/tide.c @@ -552,7 +552,7 @@ static void oninput(Rune rune) { if (win_getregion() == EDIT) { size_t point = win_buf(EDIT)->outpoint; size_t pos = win_view(EDIT)->selection.end; - if (rune == '\n' && pos > point) { + if ((rune == '\n' || rune == RUNE_CRLF) && pos > point) { Sel range = { .beg = point, .end = pos }; char* str = view_getstr(win_view(EDIT), &range); if (write(CmdFD, str, strlen(str)-1) < 0) -- 2.49.0