make selection consistent when selecting space with no text. Closes T2013

This commit is contained in:
Boris Faure 2015-01-18 19:29:39 +01:00
parent 87d653ea4d
commit e94051dd86
3 changed files with 78 additions and 44 deletions

View File

@ -2794,34 +2794,39 @@ static void
_selection_newline_extend_fix(Evas_Object *obj) _selection_newline_extend_fix(Evas_Object *obj)
{ {
Termio *sd; Termio *sd;
ssize_t w;
sd = evas_object_smart_data_get(obj); sd = evas_object_smart_data_get(obj);
if ((!sd->top_left) && (sd->pty->selection.end.y >= sd->pty->selection.start.y))
{
if (((sd->pty->selection.start.y == sd->pty->selection.end.y) &&
(sd->pty->selection.start.x <= sd->pty->selection.end.x)) ||
(sd->pty->selection.start.y < sd->pty->selection.end.y))
{
char *lastline;
int x1, y1, x2, y2;
size_t len;
if (sd->pty->selection.start.y == sd->pty->selection.end.y) x1 = sd->pty->selection.start.x; if ((sd->top_left) || (sd->bottom_right))
else x1 = 0; return;
x2 = sd->pty->selection.end.x;
y1 = y2 = sd->pty->selection.end.y; termpty_cellcomp_freeze(sd->pty);
lastline = termio_selection_get(obj, x1, y1, x2, y2, &len);
if (lastline) if ((sd->pty->selection.end.y > sd->pty->selection.start.y) ||
{ ((sd->pty->selection.end.y == sd->pty->selection.start.y) &&
if ((len > 0) && (lastline[len - 1] == '\n')) (sd->pty->selection.end.x > sd->pty->selection.start.x)))
{ {
sd->pty->selection.end.x = sd->grid.w - 1; /* going down/right */
_selection_dbl_fix(obj); w = termpty_row_length(sd->pty, sd->pty->selection.start.y);
} if (w < sd->pty->selection.start.x)
free(lastline); sd->pty->selection.start.x = w;
} w = termpty_row_length(sd->pty, sd->pty->selection.end.y);
} if (w <= sd->pty->selection.end.x)
sd->pty->selection.end.x = sd->pty->w;
} }
else
{
/* going up/left */
w = termpty_row_length(sd->pty, sd->pty->selection.end.y);
if (w < sd->pty->selection.end.x)
sd->pty->selection.end.x = w;
w = termpty_row_length(sd->pty, sd->pty->selection.start.y);
if (w <= sd->pty->selection.start.x)
sd->pty->selection.start.x = sd->pty->w;
}
termpty_cellcomp_thaw(sd->pty);
} }
/* }}} */ /* }}} */

View File

@ -580,6 +580,50 @@ termpty_cellcomp_thaw(Termpty *ty EINA_UNUSED)
termpty_save_thaw(); termpty_save_thaw();
} }
ssize_t
termpty_line_length(const Termcell *cells, ssize_t nb_cells)
{
ssize_t len = nb_cells;
for (len = nb_cells - 1; len >= 0; len--)
{
const Termcell *cell = cells + len;
if ((cell->codepoint != 0) &&
(cell->att.bg != COL_INVIS))
return len + 1;
}
return 0;
}
ssize_t
termpty_row_length(Termpty *ty, int y)
{
Termsave *ts;
if (y >= 0)
{
Termcell *cells;
if (y >= ty->h)
{
ERR("invalid row given");
return 0;
}
cells = &(TERMPTY_SCREEN(ty, 0, y));
return termpty_line_length(cells, ty->w);
}
if ((y < -ty->backmax) || !ty->back)
{
ERR("invalid row given");
return 0;
}
ts = ty->back[(ty->backmax + ty->backpos + y) % ty->backmax];
if (!ts) return 0;
return ts->comp ? ((Termsavecomp*)ts)->wout : ts->w;
}
Termcell * Termcell *
termpty_cellrow_get(Termpty *ty, int y, int *wret) termpty_cellrow_get(Termpty *ty, int y, int *wret)
{ {
@ -587,10 +631,11 @@ termpty_cellrow_get(Termpty *ty, int y, int *wret)
if (y >= 0) if (y >= 0)
{ {
Termcell *cells;
if (y >= ty->h) return NULL; if (y >= ty->h) return NULL;
*wret = ty->w; cells = &(TERMPTY_SCREEN(ty, 0, y));
/* fprintf(stderr, "getting: %i (%i, %i)\n", y, ty->circular_offset, ty->h); */ *wret = termpty_line_length(cells, ty->w);
return &(TERMPTY_SCREEN(ty, 0, y)); return cells;
} }
if ((y < -ty->backmax) || !ty->back) return NULL; if ((y < -ty->backmax) || !ty->back) return NULL;
tssrc = &(ty->back[(ty->backmax + ty->backpos + y) % ty->backmax]); tssrc = &(ty->back[(ty->backmax + ty->backpos + y) % ty->backmax]);
@ -610,23 +655,6 @@ termpty_write(Termpty *ty, const char *input, int len)
ty->fd, strerror(errno)); ty->fd, strerror(errno));
} }
ssize_t
termpty_line_length(const Termcell *cells, ssize_t nb_cells)
{
ssize_t len = nb_cells;
for (len = nb_cells - 1; len >= 0; len--)
{
const Termcell *cell = cells + len;
if ((cell->codepoint != 0) &&
(cell->att.bg != COL_INVIS))
return len + 1;
}
return 0;
}
static int static int
termpty_line_find_top(Termpty *ty, int y_end, int *top) termpty_line_find_top(Termpty *ty, int y_end, int *top)
{ {

View File

@ -226,6 +226,7 @@ void termpty_free(Termpty *ty);
void termpty_cellcomp_freeze(Termpty *ty); void termpty_cellcomp_freeze(Termpty *ty);
void termpty_cellcomp_thaw(Termpty *ty); void termpty_cellcomp_thaw(Termpty *ty);
Termcell *termpty_cellrow_get(Termpty *ty, int y, int *wret); Termcell *termpty_cellrow_get(Termpty *ty, int y, int *wret);
ssize_t termpty_row_length(Termpty *ty, int y);
void termpty_write(Termpty *ty, const char *input, int len); void termpty_write(Termpty *ty, const char *input, int len);
void termpty_resize(Termpty *ty, int w, int h); void termpty_resize(Termpty *ty, int w, int h);
void termpty_backscroll_set(Termpty *ty, int size); void termpty_backscroll_set(Termpty *ty, int size);