selection: handle scrolling and left/right margins

This commit is contained in:
Boris Faure 2018-09-29 17:21:27 +02:00
parent 9fc660ccb2
commit fccc114082
2 changed files with 108 additions and 36 deletions

View File

@ -127,35 +127,55 @@ static Eina_Bool _mouse_in_selection(Termio *sd, int cx, int cy);
/* {{{ Helpers */
void
termio_scroll(Evas_Object *obj, int direction, int start_y, int end_y)
static void
_termio_scroll_selection(Termio *sd, Termpty *ty,
int direction, int start_y, int end_y)
{
Termpty *ty;
Termio *sd = evas_object_smart_data_get(obj);
if (!ty->selection.is_active)
return;
EINA_SAFETY_ON_NULL_RETURN(sd);
int sel_start_x = ty->selection.start.x;
int sel_start_y = ty->selection.start.y;
int sel_end_x = ty->selection.end.x;
int sel_end_y = ty->selection.end.y;
if ((!sd->jump_on_change) && // if NOT scroll to bottom on updates
(sd->scroll > 0))
{
Evas_Object *mv = term_miniview_get(sd->term);
if (mv) miniview_position_offset(mv, direction, EINA_FALSE);
// adjust scroll position for added scrollback
sd->scroll -= direction;
}
ty = sd->pty;
if (ty->selection.is_active)
{
int sel_start_y, sel_end_y;
sel_start_y = ty->selection.start.y;
sel_end_y = ty->selection.end.y;
int left_margin = ty->termstate.left_margin;
int right_margin = ty->termstate.right_margin;
if (!ty->selection.is_top_to_bottom)
{
INT_SWAP(sel_start_y, sel_end_y);
INT_SWAP(sel_start_x, sel_end_x);
}
if (start_y <= sel_start_y &&
sel_end_y <= end_y)
{
if (ty->termstate.left_margin)
{
if ((ty->selection.is_box) || (sel_start_y == sel_end_y))
{
/* if selection outside scrolling area */
if ((sel_end_x <= left_margin) ||
(sel_start_x >= right_margin))
{
return;
}
/* if selection not within scrolling area */
if (!((sel_start_x >= left_margin) &&
(sel_end_x <= right_margin)))
{
_sel_set(sd, EINA_FALSE);
return;
}
}
else
{
_sel_set(sd, EINA_FALSE);
return;
}
}
ty->selection.orig.y += direction;
ty->selection.start.y += direction;
ty->selection.end.y += direction;
@ -170,6 +190,18 @@ termio_scroll(Evas_Object *obj, int direction, int start_y, int end_y)
else if (!((start_y > sel_end_y) ||
(end_y < sel_start_y)))
{
if (ty->termstate.left_margin)
{
if ((ty->selection.is_box) || (sel_start_y == sel_end_y))
{
/* if selection outside scrolling area */
if ((sel_end_x <= left_margin) ||
(sel_start_x >= right_margin))
{
return;
}
}
}
_sel_set(sd, EINA_FALSE);
}
else if (sd->scroll > 0)
@ -179,6 +211,28 @@ termio_scroll(Evas_Object *obj, int direction, int start_y, int end_y)
ty->selection.end.y += direction;
}
}
void
termio_scroll(Evas_Object *obj, int direction, int start_y, int end_y)
{
Termio *sd = evas_object_smart_data_get(obj);
Termpty *ty;
EINA_SAFETY_ON_NULL_RETURN(sd);
ty = sd->pty;
if ((!sd->jump_on_change) && // if NOT scroll to bottom on updates
(sd->scroll > 0))
{
Evas_Object *mv = term_miniview_get(sd->term);
if (mv) miniview_position_offset(mv, direction, EINA_FALSE);
// adjust scroll position for added scrollback
sd->scroll -= direction;
}
_termio_scroll_selection(sd, ty, direction, start_y, end_y);
if (sd->link.string)
{
if (sd->link.y1 <= end_y && sd->link.y2 >= start_y)

View File

@ -1,8 +1,26 @@
#/bin/bash
# fill space with E
printf '\033#8'
# cursor to 0,0
printf '\033[H'
# restrict cursor
printf '\033[?6h'
# set top/bottom margins:
printf '\033[10;20r'
# allow left/right margins
printf '\033[?69h'
# set left/right margins:
printf '\033[5;15s'
# move to 0,0 with margins:
printf '\033[H'
# clean up rect
printf '\033[1;1;11;11$z'
echo '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
I=0
while [ 1 ]; do
sleep 1
sleep 2
echo $I
I=`expr $I + 1`
done