diff options
| -rw-r--r-- | text-motions.c | 19 | ||||
| -rw-r--r-- | text-motions.h | 2 | ||||
| -rw-r--r-- | text.c | 5 | ||||
| -rw-r--r-- | vis.c | 4 | ||||
| -rw-r--r-- | window.c | 15 |
5 files changed, 23 insertions, 22 deletions
diff --git a/text-motions.c b/text-motions.c index 15fdd2d..69afcc7 100644 --- a/text-motions.c +++ b/text-motions.c @@ -78,12 +78,14 @@ size_t text_line_prev(Text *txt, size_t pos) { Iterator it = text_iterator_get(txt, pos); if (!text_iterator_byte_get(&it, &c)) return pos; - if (c == '\r') - text_iterator_byte_prev(&it, &c); if (c == '\n') text_iterator_byte_prev(&it, &c); + if (c == '\r') + text_iterator_byte_prev(&it, &c); while (text_iterator_byte_get(&it, &c) && c != '\n') text_iterator_byte_prev(&it, NULL); + if (text_iterator_byte_prev(&it, &c) && c != '\r') + text_iterator_byte_next(&it, &c); return it.pos; } @@ -92,12 +94,12 @@ size_t text_line_begin(Text *txt, size_t pos) { Iterator it = text_iterator_get(txt, pos); if (!text_iterator_byte_get(&it, &c)) return pos; - if (c == '\r') - text_iterator_byte_prev(&it, &c); if (c == '\n') text_iterator_byte_prev(&it, &c); + if (c == '\r') + text_iterator_byte_prev(&it, &c); while (text_iterator_byte_get(&it, &c)) { - if (c == '\n' || c == '\r') { + if (c == '\n') { it.pos++; break; } @@ -118,7 +120,7 @@ size_t text_line_finish(Text *txt, size_t pos) { char c; Iterator it = text_iterator_get(txt, text_line_end(txt, pos)); do text_iterator_byte_prev(&it, NULL); - while (text_iterator_byte_get(&it, &c) && c != '\n' && c != '\r' && isspace(c)); + while (text_iterator_byte_get(&it, &c) && c != '\n' && isspace(c)); if (!ISUTF8(c)) text_iterator_char_prev(&it, NULL); return it.pos; @@ -127,7 +129,7 @@ size_t text_line_finish(Text *txt, size_t pos) { size_t text_line_end(Text *txt, size_t pos) { char c; Iterator it = text_iterator_get(txt, pos); - while (text_iterator_byte_get(&it, &c) && c != '\n') + while (text_iterator_byte_get(&it, &c) && c != '\r' && c != '\n') text_iterator_byte_next(&it, NULL); return it.pos; } @@ -137,8 +139,7 @@ size_t text_line_next(Text *txt, size_t pos) { Iterator it = text_iterator_get(txt, pos); while (text_iterator_byte_get(&it, &c) && c != '\n') text_iterator_byte_next(&it, NULL); - if (text_iterator_byte_next(&it, &c) && c == '\r') - text_iterator_byte_next(&it, NULL); + text_iterator_byte_next(&it, NULL); return it.pos; } diff --git a/text-motions.h b/text-motions.h index dc9b66a..18457a5 100644 --- a/text-motions.h +++ b/text-motions.h @@ -23,7 +23,7 @@ size_t text_find_char_prev(Text*, size_t pos, const char *s, size_t len); /* begin finish next * v v v - * \n[\r] I am a line! \n[\r] + * [\r]\n I am a line! [\r]\n * ^ ^ ^ * prev start end */ @@ -1000,11 +1000,8 @@ static size_t lines_skip_forward(Text *txt, size_t pos, size_t lines) { lines--; } - if (lines == 0) { - if (start < it.end && *start == '\r') - pos++; + if (lines == 0) break; - } } return pos; } @@ -339,7 +339,7 @@ static void mark_set(const Arg *arg); static void insert(const Arg *arg); /* insert a tab or the needed amount of spaces at the current cursor position */ static void insert_tab(const Arg *arg); -/* inserts a newline (either \n or \n\r depending on file type) */ +/* inserts a newline (either \n or \r\n depending on file type) */ static void insert_newline(const Arg *arg); /* add a new line either before or after the one where the cursor currently is */ static void openline(const Arg *arg); @@ -848,7 +848,7 @@ static void insert_tab(const Arg *arg) { } static void insert_newline(const Arg *arg) { - // TODO determine file type to insert \n\r or \n + // TODO determine file type to insert \r\n or \n insert(&(const Arg){ .s = "\n" }); } @@ -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; |
