Skip to content

Commit

Permalink
Added support for backspace merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonbits committed Nov 14, 2023
1 parent 0700416 commit c09c5f0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
Binary file modified bin/aed.bin
Binary file not shown.
18 changes: 18 additions & 0 deletions src/cmd_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,26 @@ void cmd_del(screen* scr, text_buffer* buf) {
scr_del(scr, suffix, sz);
}

static void cmd_bksp_merge(screen* scr, text_buffer* buf) {
if (!tb_bksp_merge(buf)) {
return;
}
uint8_t ch = tb_peek(buf);
if (scr->currY_ > scr->topY_) {
scr->currY_--;
}
scr->currX_ = buf->x_;
if (scr->currX_ > scr->cols_-1) {
scr->currX_ = scr->cols_-1;
}
scroll_down_from_top(scr, buf, ch);
}

void cmd_bksp(screen* scr, text_buffer* buf) {
if (tb_bol(buf)) {
if (tb_ypos(buf) > 1) {
cmd_bksp_merge(scr, buf);
}
return;
}

Expand Down
15 changes: 15 additions & 0 deletions src/line_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ bool lb_merge_next(line_buffer* lb) {
return true;
}

int lb_merge_prev(line_buffer* lb) {
if (lb->curr_ == lb->buf_) {
return -1;
}

int curr = *lb->curr_;
lb->curr_--;
(*lb->curr_) -= 2;
int next = *lb->curr_;
(*lb->curr_) += curr;

return next;
}


int lb_copy(line_buffer* lb, uint8_t* buf, int size) {
const int prefix = lb->curr_ - lb->buf_+1;
int used;
Expand Down
1 change: 1 addition & 0 deletions src/line_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ bool lb_down(line_buffer* lb);
bool lb_new(line_buffer* lb, int size);
bool lb_del(line_buffer* lb);
bool lb_merge_next(line_buffer* lb);
int lb_merge_prev(line_buffer* lb);

int lb_copy(line_buffer* cb, uint8_t* buf, int size);

Expand Down
11 changes: 11 additions & 0 deletions src/text_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ bool tb_del_merge(text_buffer* tb) {
return true;
}

bool tb_bksp_merge(text_buffer* tb) {
if (!tb_bol(tb) || tb_ypos(tb) == 1) {
return false;
}
cb_bksp(&tb->cb_);
cb_bksp(&tb->cb_);

tb->x_ = lb_merge_prev(&tb->lb_);
return true;
}


// Cursor ops.
uint8_t tb_next(text_buffer* tb) {
Expand Down
1 change: 1 addition & 0 deletions src/text_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ bool tb_bksp(text_buffer* tb);
bool tb_newline(text_buffer* tb);
bool tb_del_line(text_buffer* tb);
bool tb_del_merge(text_buffer* tb);
bool tb_bksp_merge(text_buffer* tb);

// Cursor ops.
uint8_t tb_next(text_buffer* tb);
Expand Down

0 comments on commit c09c5f0

Please sign in to comment.