summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-09 14:57:58 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-09 14:57:58 -0500
commit859619b443b8d67fb262b3338015b036a1f942e1 (patch)
tree25157f43989bc79cb704186af43ea8dedf407db6
parentf9092e361420a44e6ed8e5a1fa13d3fad9f3d7de (diff)
escape command
-rw-r--r--command.c9
-rw-r--r--command.h39
-rw-r--r--main.c8
-rw-r--r--ted.cfg2
4 files changed, 31 insertions, 27 deletions
diff --git a/command.c b/command.c
index 00e9f94..6a6b331 100644
--- a/command.c
+++ b/command.c
@@ -141,7 +141,14 @@ void command_execute(Ted *ted, Command c, i64 argument) {
ted_load_font(ted);
}
} break;
-
+
+ case CMD_ESCAPE:
+ if (ted->menu) {
+ ted_menu_close(ted, true);
+ } else if (buffer) {
+ buffer_disable_selection(buffer);
+ }
+ break;
}
if (buffer && buffer_haserr(buffer)) {
diff --git a/command.h b/command.h
index db0080e..6410c3e 100644
--- a/command.h
+++ b/command.h
@@ -1,31 +1,31 @@
ENUM_U16 {
CMD_UNKNOWN,
- CMD_NOOP,
+ CMD_NOOP, // do nothing
// movement and selection commands
- CMD_LEFT,
- CMD_RIGHT,
- CMD_UP,
- CMD_DOWN,
- CMD_SELECT_LEFT,
+ CMD_LEFT, // move cursor left
+ CMD_RIGHT, // move cursor right
+ CMD_UP, // move cursor up
+ CMD_DOWN, // move cursor down
+ CMD_SELECT_LEFT, // move cursor left, and select
CMD_SELECT_RIGHT,
CMD_SELECT_UP,
CMD_SELECT_DOWN,
- CMD_LEFT_WORD,
+ CMD_LEFT_WORD, // move cursor left a word
CMD_RIGHT_WORD,
CMD_SELECT_LEFT_WORD,
CMD_SELECT_RIGHT_WORD,
- CMD_START_OF_LINE,
- CMD_END_OF_LINE,
- CMD_SELECT_START_OF_LINE,
- CMD_SELECT_END_OF_LINE,
- CMD_START_OF_FILE,
- CMD_END_OF_FILE,
+ CMD_START_OF_LINE, // move cursor to start of line
+ CMD_END_OF_LINE, // move cursor to end of line
+ CMD_SELECT_START_OF_LINE, // select to start of line
+ CMD_SELECT_END_OF_LINE, // select to end of line
+ CMD_START_OF_FILE, // move cursor to start of buffer
+ CMD_END_OF_FILE, // move cursor to end of buffer
CMD_SELECT_START_OF_FILE,
CMD_SELECT_END_OF_FILE,
- CMD_SELECT_ALL,
+ CMD_SELECT_ALL, // select entire buffer
// scrolling
- CMD_PAGE_UP,
+ CMD_PAGE_UP, // move cursor up one page up (where one page is however tall the buffer is)
CMD_PAGE_DOWN,
// deletion
@@ -34,14 +34,16 @@ ENUM_U16 {
CMD_BACKSPACE_WORD,
CMD_DELETE_WORD,
- CMD_OPEN,
- CMD_SAVE,
+ CMD_OPEN, // open a file
+ CMD_SAVE, // save current buffer
CMD_UNDO,
CMD_REDO,
CMD_TEXT_SIZE_INCREASE,
CMD_TEXT_SIZE_DECREASE,
+ CMD_ESCAPE, // by default this is the escape key. closes menus, etc.
+
CMD_COUNT
} ENUM_U16_END(Command);
@@ -84,6 +86,7 @@ static CommandName const command_names[CMD_COUNT] = {
{"undo", CMD_UNDO},
{"redo", CMD_REDO},
{"increase-text-size", CMD_TEXT_SIZE_INCREASE},
- {"decrease-text-size", CMD_TEXT_SIZE_DECREASE}
+ {"decrease-text-size", CMD_TEXT_SIZE_DECREASE},
+ {"escape", CMD_ESCAPE}
};
diff --git a/main.c b/main.c
index 85fe7b3..9f298b9 100644
--- a/main.c
+++ b/main.c
@@ -279,14 +279,6 @@ int main(int argc, char **argv) {
(u32)((modifier & (KMOD_LCTRL|KMOD_RCTRL)) != 0) << KEY_MODIFIER_CTRL_BIT |
(u32)((modifier & (KMOD_LSHIFT|KMOD_RSHIFT)) != 0) << KEY_MODIFIER_SHIFT_BIT |
(u32)((modifier & (KMOD_LALT|KMOD_RALT)) != 0) << KEY_MODIFIER_ALT_BIT;
- if (key_combo == SDL_SCANCODE_ESCAPE << 3) {
- // escape key
- if (ted->menu) {
- ted_menu_close(ted, true);
- } else if (buffer) {
- buffer_disable_selection(buffer);
- }
- }
if (key_combo < KEY_COMBO_COUNT) {
KeyAction *action = &ted->key_actions[key_combo];
if (action->command) {
diff --git a/ted.cfg b/ted.cfg
index be0ed17..c2e00df 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -60,6 +60,8 @@ Ctrl+Shift+z = :redo
Ctrl++ = 3 :increase-text-size
Ctrl+- = 3 :decrease-text-size
+Escape = :escape
+
[colors]
border = #a77
cursor-line-bg = #222