Skip to content

Commit

Permalink
repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
juliekoubova committed Jun 29, 2024
1 parent 429ccc2 commit 6da5309
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
38 changes: 6 additions & 32 deletions users/juliekoubova/vim/perform_action.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "statemachine.h"
#include "vim_mode.h"
#include "vim_send.h"
#include <stddef.h>
#include <stdbool.h>

static uint16_t command_mods = QK_LCTL;
Expand Down Expand Up @@ -66,31 +65,6 @@ void vim_set_apple(bool apple) {
line_end = apple ? LGUI(KC_RIGHT) : KC_END;
}

static void vim_send_multi(const uint16_t* code16s, size_t count) {
for (size_t i = 0; i < count; i++) {
vim_send(code16s[i], VIM_SEND_TAP);
}
}

static void vim_send_repeated_multi(int8_t repeat, const uint16_t* code16s, uint8_t code16_count) {
while (repeat > 0) {
vim_send_multi(code16s, code16_count);
repeat--;
}
}

static void vim_send_repeated(int8_t repeat, uint16_t code16, vim_send_type_t type) {
if (type == VIM_SEND_RELEASE) {
vim_send(code16, type);
return;
}
while (repeat > 1) {
vim_send(code16, VIM_SEND_TAP);
repeat--;
}
vim_send(code16, type);
}

void vim_perform_action(vim_action_t action, vim_send_type_t type) {
vim_pending_t pending = vim_clear_pending();
switch (action & VIM_MASK_ACTION) {
Expand Down Expand Up @@ -217,13 +191,13 @@ void vim_perform_action(vim_action_t action, vim_send_type_t type) {
if ((action & VIM_MASK_ACTION) == VIM_ACTION_LINE) {
type = VIM_SEND_TAP;
vim_send(line_start, type);
vim_send(LSFT(line_end), type);
vim_send(LSFT(KC_RIGHT), type);
if (pending.repeat > 1) {
const uint16_t end_left[] = {LSFT(KC_DOWN), LSFT(line_end)};
vim_send_repeated_multi(pending.repeat - 1, end_left, 2);
pending.repeat = 0;
const uint16_t end_right[] = {LSFT(line_end), LSFT(KC_RIGHT)};
uint8_t repeat = pending.repeat;
pending.repeat = 0;
if (repeat == 0) {
repeat = 1;
}
vim_send_repeated_multi(repeat, end_right, 2);
}

if (code16 != KC_NO) {
Expand Down
25 changes: 25 additions & 0 deletions users/juliekoubova/vim/vim_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,28 @@ void vim_send(uint16_t code16, vim_send_type_t type) {
}
}

void vim_send_multi(const uint16_t* code16s, size_t count) {
for (size_t i = 0; i < count; i++) {
vim_send(code16s[i], VIM_SEND_TAP);
}
}

void vim_send_repeated(int8_t repeat, uint16_t code16, vim_send_type_t type) {
if (type == VIM_SEND_RELEASE) {
vim_send(code16, type);
return;
}
while (repeat > 1) {
vim_send(code16, VIM_SEND_TAP);
repeat--;
}
vim_send(code16, type);
}

void vim_send_repeated_multi(int8_t repeat, const uint16_t* code16s, uint8_t code16_count) {
while (repeat > 0) {
vim_send_multi(code16s, code16_count);
repeat--;
}
}

5 changes: 5 additions & 0 deletions users/juliekoubova/vim/vim_send.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#pragma once
#include <stddef.h>
#include <stdint.h>

typedef enum {
Expand All @@ -24,3 +25,7 @@ typedef enum {
} vim_send_type_t;

void vim_send(uint16_t keycode, vim_send_type_t);
void vim_send_multi(const uint16_t* code16s, size_t count);
void vim_send_repeated(int8_t repeat, uint16_t code16, vim_send_type_t type);
void vim_send_repeated_multi(int8_t repeat, const uint16_t* code16s, uint8_t code16_count);

0 comments on commit 6da5309

Please sign in to comment.