From c835a9729091445bb68c5d376a8b8fd7a379cb32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 22 Jun 2020 05:44:38 -0300 Subject: Redraw page once per unicode character inserted --- jet.cpp | 68 +++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 31 deletions(-) (limited to 'jet.cpp') diff --git a/jet.cpp b/jet.cpp index 894fc69..b11744a 100644 --- a/jet.cpp +++ b/jet.cpp @@ -3,7 +3,7 @@ #include #include #include -#define PAGE_SIZE 2 +#define PAGE_SIZE 4096 #include "page.cpp" #include "point.cpp" #include "buffer.cpp" @@ -56,38 +56,44 @@ int main(int argc, char *argv[]) { } int input = getch(); - - if (mode == NORMAL_MODE) { - switch (input) { - case '': - quit = 1; - break; - case 'i': - mode = INSERT_MODE; - break; - case 'k': - buffer.prev_line(window_width); - break; - case 'j': - buffer.next_line(window_width); - break; - case 'h': - buffer.cursor--; - break; - case 'l': - buffer.cursor++; - break; + if (byte_type(input) == 1) { + if (mode == NORMAL_MODE) { + switch (input) { + case '': + quit = 1; + break; + case 'i': + mode = INSERT_MODE; + break; + case 'k': + buffer.prev_line(window_width); + break; + case 'j': + buffer.next_line(window_width); + break; + case 'h': + buffer.cursor--; + break; + case 'l': + buffer.cursor++; + break; + } + } else { + switch (input) { + case '': + mode = NORMAL_MODE; + break; + case KEY_BACKSPACE: + buffer.cursor.pop(); + break; + default: + buffer.cursor.push(input); + } } } else { - switch (input) { - case '': - mode = NORMAL_MODE; - break; - case KEY_BACKSPACE: - buffer.cursor.pop(); - break; - default: - buffer.cursor.push(input); + buffer.cursor.push(input); + for (int i = 0; i < byte_type(input) - 1; i++) { + buffer.cursor.push(getch()); } } } -- cgit v1.2.3