]> git.mdlowis.com Git - projs/tide.git/commitdiff
Fixed failing unit test
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 17 Jul 2017 13:52:23 +0000 (09:52 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 17 Jul 2017 13:52:23 +0000 (09:52 -0400)
inc/x11.h
lib/buf.c
lib/view.c
lib/win.c
tests/tide.c
tide.c

index 06a8a7e5884536cade3c80e2b70bc66b4e37039e..a22224b489590305dc1162ddceb12f66a388c6a3 100644 (file)
--- 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);
index fc81b52b651596163d5e89f19b2f58f14bc450ec..af99ee95cbfa75edab1f71d6356c1d66ad3e6f06 100644 (file)
--- 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;
index 90dbdbc66d79bc5c842294e419be5e33217901b1..eee19b71bb2d34dcf323bd0b20f9d80492624a64 100644 (file)
@@ -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;
index 6f0c1633a0f5838070ad9d0471e21f0a37ce94f2..7b6275dce88e8e73fcd2e31a69c62e7ce94fc3cf 100644 (file)
--- 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);
-        }
     }
 }
 
index 9885022571e48f5c07429b02fd9c143adfe30c98..8af7b28182cd8c9a185bfe7a9a1c86f1e4ce765a 100644 (file)
@@ -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 3712d23f3dcfef28eae64f049935df92ee2fe450..47466df78ed608669f658f3e0cfc73a924028b73 100644 (file)
--- 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)