summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-12-31 14:11:25 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-12-31 14:11:25 -0500
commitd7ae78179cf18bc79703ac2199e0ae03e556430f (patch)
tree3b580699a0a9f5dc2fb41d54936b19aeb90904e9
parent185bf5b364efb4d7885ff5adcb69204e892ff5f7 (diff)
page up/down
-rw-r--r--buffer.c8
-rw-r--r--command.c7
-rw-r--r--command.h9
-rw-r--r--ted.cfg7
4 files changed, 29 insertions, 2 deletions
diff --git a/buffer.c b/buffer.c
index e699548..c79a2df 100644
--- a/buffer.c
+++ b/buffer.c
@@ -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;
diff --git a/command.c b/command.c
index 4f1bb89..69ce9ee 100644
--- a/command.c
+++ b/command.c
@@ -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);
diff --git a/command.h b/command.h
index df6bf74..1057b4b 100644
--- a/command.h
+++ b/command.h
@@ -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},
};
diff --git a/ted.cfg b/ted.cfg
index ff97637..ba0ffb5 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -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
+