]> git.mdlowis.com Git - projs/tide.git/commitdiff
first pass at detecting dos line endings
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 17 Sep 2018 18:38:09 +0000 (14:38 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 17 Sep 2018 18:38:09 +0000 (14:38 -0400)
TODO.md
lib/buf.c
lib/view.c

diff --git a/TODO.md b/TODO.md
index 80edc471d918b76238acfab279367d7d2a604271..fa52cf8122903e89076fe6afb250b68768016508 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -9,6 +9,7 @@ BUGS:
 * no trimming of trailing whitespace
 * gap buffer does not handle UTF-8 currently
 * mouse selection handling when mouse moves outside region
+* move mouse handlers back into tide.c
 
 Up Next:
 
index cfe47b567c9f1a7b8b9e5bd367ccc333e759c89f..63e9950876aa06c35767a739d96775364133315e 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -424,7 +424,7 @@ static int bytes_match(Buf* buf, size_t mbeg, size_t mend, char* str) {
 
 bool buf_iseol(Buf* buf, size_t off) {
     Rune r = buf_getrat(buf, off);
-    return (r == '\n');
+    return (r == '\r' || r == '\n');
 }
 
 size_t buf_bol(Buf* buf, size_t off) {
index f8ac1818da65fdb5b60256c4dca9ce8fb5e8fd8d..31bde213b56adafa342303d83316f7e98ff878d7 100644 (file)
@@ -74,7 +74,11 @@ void view_init(View* view, char* file) {
     view->nvisible = 0;
     /* load the file and jump to the address returned from the load function */
     buf_init(BUF);
-    if (file) buf_load(BUF, file);
+    if (file) {
+        buf_load(BUF, file);
+        /* use the EOL style of the first line to determine EOL style */
+        DosLineFeed = (buf_getrat(BUF, buf_eol(BUF, 0)) == '\r');
+    }
 }
 
 void view_reload(View* view) {
@@ -263,11 +267,13 @@ void view_insert(View* view, Rune rune) {
         size_t off = buf_selbeg(BUF);
         size_t n = (TabWidth - ((off - buf_bol(BUF, off)) % TabWidth));
         for (; n > 0; n--) buf_putc(BUF, ' ');
-     } else if (CopyIndent && rune == '\n') {
+    } else if (CopyIndent && rune == '\n') {
          size_t off = buf_selbeg(BUF);
          size_t beg = buf_bol(BUF, off-1), end = beg;
          for (; end < buf_end(BUF) && (' ' == buf_getrat(BUF, end) || '\t' == buf_getrat(BUF, end)); end++);
-        buf_putc(BUF, rune); 
+        if (DosLineFeed) 
+            buf_putc(BUF, '\r'); 
+        buf_putc(BUF, '\n'); 
         for (; beg < end; beg++)
              buf_putc(BUF, buf_getrat(BUF, beg));
     } else {