From a71ab3700681256c7ecbff6340b43fbf2ff77d74 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 9 Oct 2016 18:44:54 -0400 Subject: [PATCH] Added TargetCol updates to home and end key handlers --- TODO.md | 2 -- keyboard.c | 14 ++++++++++++-- xedit.c | 8 ++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index c5a4291..39689ed 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,5 @@ # Internals and Miscellaneous -* Re-work column tracking to keep the cursor reasonably close to where expected * Calculate line numbers and keep up to date while editing * Support multiple buffers * Implement undo/redo log @@ -13,7 +12,6 @@ # Unicode * Fix display of asian scripts and combining characters -* Read the file in bytewise and detect the encoding and line endings. Use that info to perform cursor movements and redisplay. # Graphical User Interface diff --git a/keyboard.c b/keyboard.c index 8014269..983320c 100644 --- a/keyboard.c +++ b/keyboard.c @@ -24,6 +24,16 @@ static void cursor_right(void) { TargetCol = buf_getcol(&Buffer, CursorPos); } +static void cursor_home(void) { + CursorPos = buf_bol(&Buffer, CursorPos); + TargetCol = 0; +} + +static void cursor_end(void) { + CursorPos = buf_eol(&Buffer, CursorPos); + TargetCol = (unsigned)-1; +} + void handle_key(Rune key) { /* ignore invalid keys */ if (key == RUNE_ERR) return; @@ -49,8 +59,8 @@ static void special_keys(Rune key) { case KEY_INSERT: Buffer.insert_mode = !Buffer.insert_mode; break; case KEY_F1: Buffer.insert_mode = !Buffer.insert_mode; break; case KEY_DELETE: buf_del(&Buffer, CursorPos); break; - case KEY_HOME: CursorPos = buf_bol(&Buffer, CursorPos); break; - case KEY_END: CursorPos = buf_eol(&Buffer, CursorPos); break; + case KEY_HOME: cursor_home(); break; + case KEY_END: cursor_end(); break; } } diff --git a/xedit.c b/xedit.c index 4cbdbd4..b2281b1 100644 --- a/xedit.c +++ b/xedit.c @@ -216,10 +216,11 @@ static void redraw(void) { /* flush the screen buffer */ unsigned nrows, ncols; screen_getsize(&nrows, &ncols); - screen_status(" %s %s%s", + screen_status(" %s %c %s", (Buffer.charset == BINARY ? "BIN" : "UTF-8"), - (Buffer.modified ? " * " : " "), - Buffer.path); + (Buffer.modified ? '*' : ' '), + Buffer.path + ); for (unsigned y = 0; y < nrows; y++) { Row* row = screen_getrow(y); XftDrawString32(X.xft, (y==0 ? &bkgclr : &txtclr), X.font, 0, (y+1) * fheight, (FcChar32*)(row->cols), (row->len)); @@ -257,6 +258,5 @@ int main(int argc, char** argv) { } redraw(); } - deinit(); return 0; } -- 2.49.0