diff options
author | Kent Overstreet <kmo@daterainc.com> | 2014-03-19 14:35:39 -0700 |
---|---|---|
committer | Kent Overstreet <kmo@daterainc.com> | 2014-03-19 14:35:39 -0700 |
commit | a9cf1f312dcde7284093629224354c853f6efcae (patch) | |
tree | fb0cda1a717097272e176152142147680623c24e | |
parent | 7f67bc36a7cc05e8e388382922113fe4551f23ef (diff) |
-rw-r--r-- | term.c | 43 |
1 files changed, 36 insertions, 7 deletions
@@ -139,9 +139,12 @@ void term_sel_update(struct st_term *term, unsigned type, sel->p1 = start; sel->p2 = end; + if (sel->type == SEL_NONE) + sel->type = type; + switch (sel->type) { case SEL_NONE: - sel->type = type; + assert(0); break; case SEL_REGULAR: if (sel->p1.y > sel->p2.y || @@ -175,13 +178,39 @@ void term_sel_word(struct st_term *term, struct coord pos) { struct coord start = pos; - while (start.x && - isword(term_pos(term, start)[-1].c)) - start.x--; + while (1) { + struct coord prev = start; + + if (prev.x) { + prev.x--; + } else if (prev.y) { + prev.y--; + prev.x = term->size.x - 1; + } else + break; + + if (!isword(term_pos(term, prev)->c)) + break; + + start = prev; + } + + while (1) { + struct coord next = pos; + + if (next.x < term->size.x - 1) { + next.x++; + } else if (next.y < term->size.y - 1) { + next.y++; + next.x = 0; + } else + break; + + if (!isword(term_pos(term, next)->c)) + break; - while (pos.x < term->size.x - 1 && - isword(term_pos(term, pos)[1].c)) - pos.x++; + pos = next; + } term_sel_update(term, SEL_REGULAR, start, pos); } |