forked from enlightenment/terminology
make selection consistent when selecting space with no text. Closes T2013
This commit is contained in:
parent
87d653ea4d
commit
e94051dd86
|
@ -2794,34 +2794,39 @@ static void
|
|||
_selection_newline_extend_fix(Evas_Object *obj)
|
||||
{
|
||||
Termio *sd;
|
||||
ssize_t w;
|
||||
|
||||
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;
|
||||
else x1 = 0;
|
||||
x2 = sd->pty->selection.end.x;
|
||||
y1 = y2 = sd->pty->selection.end.y;
|
||||
lastline = termio_selection_get(obj, x1, y1, x2, y2, &len);
|
||||
if (lastline)
|
||||
{
|
||||
if ((len > 0) && (lastline[len - 1] == '\n'))
|
||||
{
|
||||
sd->pty->selection.end.x = sd->grid.w - 1;
|
||||
_selection_dbl_fix(obj);
|
||||
}
|
||||
free(lastline);
|
||||
}
|
||||
}
|
||||
if ((sd->top_left) || (sd->bottom_right))
|
||||
return;
|
||||
|
||||
termpty_cellcomp_freeze(sd->pty);
|
||||
|
||||
if ((sd->pty->selection.end.y > sd->pty->selection.start.y) ||
|
||||
((sd->pty->selection.end.y == sd->pty->selection.start.y) &&
|
||||
(sd->pty->selection.end.x > sd->pty->selection.start.x)))
|
||||
{
|
||||
/* going down/right */
|
||||
w = termpty_row_length(sd->pty, sd->pty->selection.start.y);
|
||||
if (w < sd->pty->selection.start.x)
|
||||
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);
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
|
|
@ -580,6 +580,50 @@ termpty_cellcomp_thaw(Termpty *ty EINA_UNUSED)
|
|||
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 *
|
||||
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)
|
||||
{
|
||||
Termcell *cells;
|
||||
if (y >= ty->h) return NULL;
|
||||
*wret = ty->w;
|
||||
/* fprintf(stderr, "getting: %i (%i, %i)\n", y, ty->circular_offset, ty->h); */
|
||||
return &(TERMPTY_SCREEN(ty, 0, y));
|
||||
cells = &(TERMPTY_SCREEN(ty, 0, y));
|
||||
*wret = termpty_line_length(cells, ty->w);
|
||||
return cells;
|
||||
}
|
||||
if ((y < -ty->backmax) || !ty->back) return NULL;
|
||||
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));
|
||||
}
|
||||
|
||||
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
|
||||
termpty_line_find_top(Termpty *ty, int y_end, int *top)
|
||||
{
|
||||
|
|
|
@ -226,6 +226,7 @@ void termpty_free(Termpty *ty);
|
|||
void termpty_cellcomp_freeze(Termpty *ty);
|
||||
void termpty_cellcomp_thaw(Termpty *ty);
|
||||
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_resize(Termpty *ty, int w, int h);
|
||||
void termpty_backscroll_set(Termpty *ty, int size);
|
||||
|
|
Loading…
Reference in New Issue