summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--term.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/term.c b/term.c
index abe03f6..e016ce2 100644
--- a/term.c
+++ b/term.c
@@ -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);
}