tsoding / ded

Dramatic EDitor
MIT License
570 stars 76 forks source link

Fix last keystroke time not being updated on certain keys #76

Open mjkloeckner opened 1 year ago

mjkloeckner commented 1 year ago

I noticed that while pressing tab the cursor last keystroke was not being updated:

case SDLK_TAB: {
    for (size_t i = 0; i < 4; ++i) {
        editor_insert_char(&editor, ' ');
    }
}

it should be:

case SDLK_TAB: {
    for (size_t i = 0; i < 4; ++i) {
        editor_insert_char(&editor, ' ');
    }
    editor.last_stroke = SDL_GetTicks();
}

but instead of updating the last keystroke individually in every key press, it's better to update it when a key is pressed regardless if the key being pressed has a dedicated function or not.

This commit removes all the editor.last_stroke = SDL_GetTicks(); from every key case and adds only one after the switch execution.