Fix rx_to_cx bug
This commit is contained in:
parent
33f9102767
commit
257f90cff9
2 changed files with 9 additions and 11 deletions
|
@ -82,6 +82,7 @@ void command_insert_char(char c) {
|
||||||
input_process_key(ARROW_RIGHT);
|
input_process_key(ARROW_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Is this many simulated keypresses necessary? Is it bad?
|
||||||
void command_delete_char(void) {
|
void command_delete_char(void) {
|
||||||
if (E.current_buf->cy == E.current_buf->n_rows)
|
if (E.current_buf->cy == E.current_buf->n_rows)
|
||||||
input_process_key(ARROW_LEFT);
|
input_process_key(ARROW_LEFT);
|
||||||
|
@ -94,6 +95,7 @@ void command_delete_char(void) {
|
||||||
|
|
||||||
struct erow *prow = E.current_buf->rows[E.current_buf->cy - 1];
|
struct erow *prow = E.current_buf->rows[E.current_buf->cy - 1];
|
||||||
|
|
||||||
|
input_process_key(HOME);
|
||||||
input_process_key(ARROW_UP);
|
input_process_key(ARROW_UP);
|
||||||
cursor_move(E.current_buf, prow->n_chars, 0);
|
cursor_move(E.current_buf, prow->n_chars, 0);
|
||||||
|
|
||||||
|
|
18
src/erow.c
18
src/erow.c
|
@ -55,9 +55,8 @@ int erow_cx_to_rx(struct erow *erow, int cx) {
|
||||||
cx = CLAMP(cx, 0, (int) erow->n_chars);
|
cx = CLAMP(cx, 0, (int) erow->n_chars);
|
||||||
|
|
||||||
int rx = 0;
|
int rx = 0;
|
||||||
|
for (int c_cx = 0; c_cx < cx; c_cx++) {
|
||||||
for (char *c = erow->chars; c < erow->chars + cx; c++) {
|
if (erow->chars[c_cx] == '\t')
|
||||||
if (*c == '\t')
|
|
||||||
rx += KILO_TAB_STOP - (rx % KILO_TAB_STOP);
|
rx += KILO_TAB_STOP - (rx % KILO_TAB_STOP);
|
||||||
else
|
else
|
||||||
rx++;
|
rx++;
|
||||||
|
@ -70,20 +69,17 @@ int erow_rx_to_cx(struct erow *erow, int rx) {
|
||||||
if (erow == NULL)
|
if (erow == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int cx = 0, c_rx = 0;
|
rx = CLAMP(rx, 0, (int) erow->n_rchars);
|
||||||
while ((size_t) cx < erow->n_chars) {
|
|
||||||
|
int cx = 0;
|
||||||
|
for (int c_rx = 0; c_rx < rx; cx++) {
|
||||||
if (erow->chars[cx] == '\t')
|
if (erow->chars[cx] == '\t')
|
||||||
c_rx += KILO_TAB_STOP - (c_rx % KILO_TAB_STOP);
|
c_rx += KILO_TAB_STOP - (c_rx % KILO_TAB_STOP);
|
||||||
else
|
else
|
||||||
c_rx++;
|
c_rx++;
|
||||||
|
|
||||||
cx++;
|
|
||||||
|
|
||||||
if (c_rx >= rx)
|
|
||||||
return cx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return erow->n_chars;
|
return cx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void erow_free(struct erow *erow) {
|
void erow_free(struct erow *erow) {
|
||||||
|
|
Reference in a new issue