billiob pushed a commit to branch master. http://git.enlightenment.org/apps/terminology.git/commit/?id=8c7dab9fdfa821199098080ff3467407213dfbfa
commit 8c7dab9fdfa821199098080ff3467407213dfbfa Author: Boris Faure <[email protected]> Date: Mon Nov 11 18:08:02 2013 +0100 remove selection when content selected changes --- src/bin/termio.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++---- src/bin/termio.h | 1 + src/bin/termptyops.c | 17 ++++++++++--- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/src/bin/termio.c b/src/bin/termio.c index 86a37c9..a574b27 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -108,6 +108,7 @@ static void _sel_set(Evas_Object *obj, Eina_Bool enable) { Termio *sd = evas_object_smart_data_get(obj); + if (sd->pty->selection.is_active == enable) return; sd->pty->selection.is_active = enable; if (enable) @@ -3276,7 +3277,6 @@ _smart_cb_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUS sd = evas_object_smart_data_get(data); if (!sd) return; - DBG("(%d; %d)", ev->cur.canvas.y, ev->cur.canvas.x); evas_object_geometry_get(data, &ox, &oy, NULL, NULL); cx = (ev->cur.canvas.x - ox) / sd->font.chw; cy = (ev->cur.canvas.y - oy) / sd->font.chh; @@ -3946,7 +3946,6 @@ termio_scroll(Evas_Object *obj, int direction) { Termio *sd; Termpty *ty; - int changed = 0; sd = evas_object_smart_data_get(obj); if (!sd) return; @@ -3958,16 +3957,76 @@ termio_scroll(Evas_Object *obj, int direction) sd->scroll++; if (sd->scroll > sd->pty->backscroll_num) sd->scroll = sd->pty->backscroll_num; - changed = 1; } ty = sd->pty; if (ty->selection.is_active) { ty->selection.start.y += direction; ty->selection.end.y += direction; - changed = 1; } - if (changed) _smart_update_queue(obj, sd); +} + +void +termio_content_change(Evas_Object *obj, Evas_Coord x, Evas_Coord y, + int n) +{ + Termio *sd; + Termpty *ty; + int start_x, start_y, end_x, end_y; + + sd = evas_object_smart_data_get(obj); + if (!sd) return; + ty = sd->pty; + if (!ty->selection.is_active) return; + + start_x = sd->pty->selection.start.x; + start_y = sd->pty->selection.start.y; + end_x = sd->pty->selection.end.x; + end_y = sd->pty->selection.end.y; + if (ty->selection.is_box) + { + int _y = y + (x + n) / ty->w; + + if (start_y > end_y) + INT_SWAP(start_y, end_y); + if (start_x > end_x) + INT_SWAP(start_x, end_x); + + y = MAX(y, start_y); + for (; y <= MIN(_y, end_y); y++) + { + int d = MIN(n, ty->w - x); + if (!((x > end_x) || (x + d < start_x))) + { + _sel_set(obj, EINA_FALSE); + break; + } + n -= d; + x = 0; + } + } + else + { + int sel_len; + Termcell *cells_changed, *cells_selection; + + /* probably doing that way too much… */ + if ((start_y > end_y) || + ((start_y == end_y) && (end_x < start_x))) + { + INT_SWAP(start_y, end_y); + INT_SWAP(start_x, end_x); + } + + sel_len = end_x - start_y + ty->w * (end_y - start_y); + cells_changed = &(TERMPTY_SCREEN(ty, x, y)); + cells_selection = &(TERMPTY_SCREEN(ty, start_x, start_y)); + + if (!((cells_changed > (cells_selection + sel_len)) || + (cells_selection > (cells_changed + n)))) + _sel_set(obj, EINA_FALSE); + + } } static void diff --git a/src/bin/termio.h b/src/bin/termio.h index 51969c4..fd3867f 100644 --- a/src/bin/termio.h +++ b/src/bin/termio.h @@ -13,6 +13,7 @@ char *termio_selection_get(Evas_Object *obj, size_t *len); Eina_Bool termio_selection_exists(const Evas_Object *obj); void termio_scroll(Evas_Object *obj, int direction); +void termio_content_change(Evas_Object *obj, Evas_Coord x, Evas_Coord y, int n); void termio_config_update(Evas_Object *obj); Config *termio_config_get(const Evas_Object *obj); diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c index aa1a631..1e6e8c6 100644 --- a/src/bin/termptyops.c +++ b/src/bin/termptyops.c @@ -174,6 +174,8 @@ _termpty_text_append(Termpty *ty, const Eina_Unicode *codepoints, int len) Termcell *cells; int i, j; + termio_content_change(ty->obj, ty->state.cx, ty->state.cy, len); + cells = &(TERMPTY_SCREEN(ty, 0, ty->state.cy)); for (i = 0; i < len; i++) { @@ -244,13 +246,13 @@ _termpty_clear_line(Termpty *ty, Termpty_Clear mode, int limit) { Termcell *cells; int n = 0; + Evas_Coord x = 0, y = ty->state.cy; - cells = &(TERMPTY_SCREEN(ty, 0, ty->state.cy)); switch (mode) { case TERMPTY_CLR_END: n = ty->w - ty->state.cx; - cells = &(cells[ty->state.cx]); + x = ty->state.cx; break; case TERMPTY_CLR_BEGIN: n = ty->state.cx + 1; @@ -261,7 +263,9 @@ _termpty_clear_line(Termpty *ty, Termpty_Clear mode, int limit) default: return; } + cells = &(TERMPTY_SCREEN(ty, x, y)); if (n > limit) n = limit; + termio_content_change(ty->obj, x, y, n); _text_clear(ty, cells, n, 0, EINA_TRUE); } @@ -278,6 +282,8 @@ _termpty_clear_screen(Termpty *ty, Termpty_Clear mode) { int l = ty->h - (ty->state.cy + 1); + termio_content_change(ty->obj, 0, ty->state.cy, l * ty->w); + while (l) { cells = &(TERMPTY_SCREEN(ty, 0, (ty->state.cy + l))); @@ -292,6 +298,8 @@ _termpty_clear_screen(Termpty *ty, Termpty_Clear mode) // First clear from circular > height, then from 0 to circular int y = ty->state.cy + ty->circular_offset; + termio_content_change(ty->obj, 0, 0, ty->state.cy * ty->w); + cells = &(TERMPTY_SCREEN(ty, 0, 0)); if (y < ty->h) @@ -313,12 +321,13 @@ _termpty_clear_screen(Termpty *ty, Termpty_Clear mode) ty->circular_offset = 0; _text_clear(ty, ty->screen, ty->w * ty->h, 0, EINA_TRUE); ty->state.scroll_y2 = 0; + ERR("foo"); + if (ty->cb.cancel_sel.func) + ty->cb.cancel_sel.func(ty->cb.cancel_sel.data); break; default: break; } - if (ty->cb.cancel_sel.func) - ty->cb.cancel_sel.func(ty->cb.cancel_sel.data); } void --
