summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/main.c b/main.c
index 8d15c1b..974bc8a 100644
--- a/main.c
+++ b/main.c
@@ -5,7 +5,6 @@ FUTURE FEATURES:
- better undo chaining (dechain on backspace?)
- manual.md
- regenerate tags for completion too if there are no results
-- make go-to-definition/hover/highlight modifier key configurable
- font setting & support for multiple fonts to cover more characters
- support for variable-width fonts
- robust find (results shouldn't move around when you type things)
@@ -602,28 +601,21 @@ int main(int argc, char **argv) {
double frame_start = time_get_seconds();
ted->frame_time = frame_start;
- SDL_Event event;
- Uint8 const *keyboard_state = SDL_GetKeyboardState(NULL);
-
+ SDL_PumpEvents();
+ u32 key_modifier = ted_get_key_modifier(ted);
{ // get mouse position
int mouse_x = 0, mouse_y = 0;
ted->mouse_state = SDL_GetMouseState(&mouse_x, &mouse_y);
ted->mouse_pos = Vec2((float)mouse_x, (float)mouse_y);
}
- bool ctrl_down = keyboard_state[SDL_SCANCODE_LCTRL] || keyboard_state[SDL_SCANCODE_RCTRL];
- bool shift_down = keyboard_state[SDL_SCANCODE_LSHIFT] || keyboard_state[SDL_SCANCODE_RSHIFT];
- bool alt_down = keyboard_state[SDL_SCANCODE_LALT] || keyboard_state[SDL_SCANCODE_RALT];
memset(ted->nmouse_clicks, 0, sizeof ted->nmouse_clicks);
memset(ted->nmouse_releases, 0, sizeof ted->nmouse_releases);
ted->scroll_total_x = ted->scroll_total_y = 0;
ted_update_window_dimensions(ted);
- u32 key_modifier = (u32)ctrl_down << KEY_MODIFIER_CTRL_BIT
- | (u32)shift_down << KEY_MODIFIER_SHIFT_BIT
- | (u32)alt_down << KEY_MODIFIER_ALT_BIT;
- ted->key_modifier = key_modifier;
+ SDL_Event event;
while (SDL_PollEvent(&event)) {
TextBuffer *buffer = ted->active_buffer;
@@ -632,7 +624,7 @@ int main(int argc, char **argv) {
command_execute(ted, CMD_QUIT, 1);
break;
case SDL_MOUSEWHEEL: {
- if (ctrl_down) {
+ if (ted_is_ctrl_down(ted)) {
// adjust text size with ctrl+scroll
Settings *settings = ted_active_settings(ted);
scroll_wheel_text_size_change += settings->ctrl_scroll_adjust_text_size * event.wheel.preciseY;
@@ -840,16 +832,16 @@ int main(int argc, char **argv) {
TextBuffer *active_buffer = ted->active_buffer;
if (active_buffer && key_modifier == KEY_MODIFIER_ALT) {
// alt + arrow keys to scroll
- double scroll_speed = 20.0;
+ double scroll_speed = 40.0;
double scroll_amount_x = scroll_speed * frame_dt * 1.5; // characters are taller than they are wide
double scroll_amount_y = scroll_speed * frame_dt;
- if (keyboard_state[SDL_SCANCODE_UP])
+ if (ted_is_key_down(ted, SDLK_UP))
buffer_scroll(active_buffer, 0, -scroll_amount_y);
- if (keyboard_state[SDL_SCANCODE_DOWN])
+ if (ted_is_key_down(ted, SDLK_DOWN))
buffer_scroll(active_buffer, 0, +scroll_amount_y);
- if (keyboard_state[SDL_SCANCODE_LEFT])
+ if (ted_is_key_down(ted, SDLK_LEFT))
buffer_scroll(active_buffer, -scroll_amount_x, 0);
- if (keyboard_state[SDL_SCANCODE_RIGHT])
+ if (ted_is_key_down(ted, SDLK_RIGHT))
buffer_scroll(active_buffer, +scroll_amount_x, 0);
}