diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-12-31 14:11:25 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-12-31 14:11:25 -0500 |
commit | d7ae78179cf18bc79703ac2199e0ae03e556430f (patch) | |
tree | 3b580699a0a9f5dc2fb41d54936b19aeb90904e9 | |
parent | 185bf5b364efb4d7885ff5adcb69204e892ff5f7 (diff) |
page up/down
-rw-r--r-- | buffer.c | 8 | ||||
-rw-r--r-- | command.c | 7 | ||||
-rw-r--r-- | command.h | 9 | ||||
-rw-r--r-- | ted.cfg | 7 |
4 files changed, 29 insertions, 2 deletions
@@ -695,6 +695,14 @@ void buffer_scroll(TextBuffer *buffer, double dx, double dy) { buffer_correct_scroll(buffer); } +void buffer_page_up(TextBuffer *buffer, i64 npages) { + buffer_scroll(buffer, 0, (double)(-npages * buffer_display_lines(buffer))); +} + +void buffer_page_down(TextBuffer *buffer, i64 npages) { + buffer_scroll(buffer, 0, (double)(+npages * buffer_display_lines(buffer))); +} + // returns the position of the character at the given position in the buffer. v2 buffer_pos_to_pixels(TextBuffer *buffer, BufferPos pos) { u32 line = pos.line, index = pos.index; @@ -100,6 +100,13 @@ void command_execute(Ted *ted, Command c, i64 argument) { case CMD_DELETE_WORD: buffer_delete_words_at_cursor(buffer, argument); break; + + case CMD_PAGE_DOWN: + buffer_page_down(buffer, argument); + break; + case CMD_PAGE_UP: + buffer_page_up(buffer, argument); + break; case CMD_SAVE: buffer_save(buffer); @@ -23,6 +23,10 @@ ENUM_U16 { CMD_SELECT_START_OF_FILE, CMD_SELECT_END_OF_FILE, + // scrolling + CMD_PAGE_UP, + CMD_PAGE_DOWN, + // deletion CMD_BACKSPACE, CMD_DELETE, @@ -40,7 +44,6 @@ typedef struct { char const *name; Command cmd; } CommandName; - static CommandName const command_names[CMD_COUNT] = { {"unknown", CMD_UNKNOWN}, {"noop", CMD_NOOP}, @@ -64,12 +67,14 @@ static CommandName const command_names[CMD_COUNT] = { {"end-of-file", CMD_END_OF_FILE}, {"select-start-of-file", CMD_SELECT_START_OF_FILE}, {"select-end-of-file", CMD_SELECT_END_OF_FILE}, + {"page-up", CMD_PAGE_UP}, + {"page-down", CMD_PAGE_DOWN}, {"backspace", CMD_BACKSPACE}, {"delete", CMD_DELETE}, {"backspace-word", CMD_BACKSPACE_WORD}, {"delete-word", CMD_DELETE_WORD}, {"save", CMD_SAVE}, {"undo", CMD_UNDO}, - {"redo", CMD_REDO} + {"redo", CMD_REDO}, }; @@ -31,6 +31,13 @@ Ctrl+Delete = :delete-word Backspace = :backspace Ctrl+Backspace = :backspace-word +# scrolling +PageUp = :page-up +PageDown = :page-down +Ctrl+PageUp = 10 :page-up +Ctrl+PageDown = 10 :page-down + Ctrl+s = :save Ctrl+z = :undo Ctrl+Shift+z = :redo + |