Skip to content

Commit

Permalink
Initial line-return functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
newsch committed May 9, 2019
1 parent e0405e4 commit d9573f1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/fe_modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ mode_brush_config_t mode_brush_config = {
.state = PAINT_OFF,
};

typedef struct {
Cursor *last_dir_change;
} mode_insert_config_t;

mode_insert_config_t mode_insert_config = {NULL};

///////////////////////
// GENERAL FUNCTIONS //
///////////////////////
Expand Down Expand Up @@ -267,11 +273,22 @@ int mode_insert(reason_t reason, State *state) {
return 0;
}

mode_insert_config_t *mode_cfg = &mode_insert_config;
// init config cursor
if (mode_cfg->last_dir_change == NULL) {
mode_cfg->last_dir_change = cursor_copy(state->cursor);
}

// insert mode behavior
if ((state->ch_in == KEY_LEFT) || (state->ch_in == KEY_RIGHT) ||
(state->ch_in == KEY_UP) || (state->ch_in == KEY_DOWN)) {
cursor_key_to_move(state->ch_in, state->cursor, state->view);
state->last_arrow_direction = state->ch_in;

// update direction change cursor
Cursor *old = mode_cfg->last_dir_change;
mode_cfg->last_dir_change = cursor_copy(state->cursor);
cursor_free(old);
} else {
if (' ' <= state->ch_in &&
state->ch_in <= '~') { // check if ch is printable
Expand All @@ -284,6 +301,22 @@ int mode_insert(reason_t reason, State *state) {
front_setcharcursor(' ');
} else if (state->ch_in == KEY_DC) {
front_setcharcursor(' ');
} else if (state->ch_in == KEY_ENTER) {
// return to beginning of "line" on ENTER
// TODO: check if out of view and recenter
if (state->last_arrow_direction == KEY_RIGHT ||
state->last_arrow_direction == KEY_LEFT) {
// return down if left/right
state->cursor->x = mode_cfg->last_dir_change->x;
state->cursor->y++;
mode_cfg->last_dir_change->y = state->cursor->y;
} else if (state->last_arrow_direction == KEY_UP ||
state->last_arrow_direction == KEY_DOWN) {
// return right if up/down
state->cursor->y = mode_cfg->last_dir_change->y;
state->cursor->x++;
mode_cfg->last_dir_change->x = state->cursor->x;
}
}
}
return 0;
Expand Down

0 comments on commit d9573f1

Please sign in to comment.