termiointernals: fix regression on selecting word at start of line

In case of double-click.
terminology-1.4
Boris Faure 3 years ago
parent 3378f033f5
commit 1ce26c51f7
  1. 20
      src/bin/termiointernals.c
  2. 94
      tests/selection_word_regression.sh
  3. 1
      tests/tests.results

@ -873,15 +873,20 @@ _sel_word(Termio *sd, int cx, int cy)
goto end;
}
if (x >= w)
x = w - 1;
{
x = w - 1;
}
/* To the left and up */
do
{
for (; x >= 0; x--)
{
if ((cells[x].codepoint == 0) && (cells[x].att.dblwidth) &&
(x > 0))
x--;
{
x--;
}
if (_codepoint_is_wordsep(cells[x].codepoint))
{
done = EINA_TRUE;
@ -893,12 +898,14 @@ _sel_word(Termio *sd, int cx, int cy)
if (!done)
{
Termcell *old_cells = cells;
size_t old_w = w;
cells = termpty_cellrow_get(sd->pty, y - 1, &w);
if (!cells || !cells[w-1].att.autowrapped)
if ((!cells) || (w == 0) || (!cells[w-1].att.autowrapped))
{
x = 0;
x = cx;
cells = old_cells;
w = old_w;
done = EINA_TRUE;
}
else
@ -922,6 +929,7 @@ _sel_word(Termio *sd, int cx, int cy)
}
x = cx;
/* To the right and down */
do
{
for (; x < w; x++)
@ -943,7 +951,9 @@ _sel_word(Termio *sd, int cx, int cy)
if (!done)
{
if (!cells[w - 1].att.autowrapped)
goto end;
{
goto end;
}
y++;
x = 0;
cells = termpty_cellrow_get(sd->pty, y, &w);

@ -0,0 +1,94 @@
#!/bin/sh
# char width: 7
# char height: 15
# clear screen
printf '\033[2J'
# set color
printf '\033[46;31;3m'
#move to 2,0
printf '\033[2H'
# set text
printf "Insanity is doing the same thing, over and over again, but expecting different results"
# force render
printf '\033}tr\0'
## Select simple word: "thing"
# double-click to select word
printf '\033}td;200;20;1;0;0\0'
printf '\033}tu;200;20;1;0;0\0'
printf '\033}td;200;20;1;0;1\0'
printf '\033}tu;200;20;1;0;1\0'
# force render
printf '\033}tr\0'
# assert selection is
printf '\033}tsthing\0'
# remove selection
printf '\033}td;0;0;1;0;0\0\033}tu;0;0;1;0;0\0'
printf '\033}tc;0;0\0\033}tc;1;0\0'
## Select last word: "results"
# double-click to select word
printf '\033}td;20;35;1;0;0\0'
printf '\033}tu;20;35;1;0;0\0'
printf '\033}td;20;35;1;0;1\0'
printf '\033}tu;20;35;1;0;1\0'
# force render
printf '\033}tr\0'
# assert selection is
printf '\033}tsresults\0'
# remove selection
printf '\033}td;0;0;1;0;0\0\033}tu;0;0;1;0;0\0'
printf '\033}tc;0;0\0\033}tc;1;0\0'
## Same but by the start of the word, at the end of the previous line
# double-click to select word
printf '\033}td;555;20;1;0;0\0'
printf '\033}tu;555;20;1;0;0\0'
printf '\033}td;555;20;1;0;1\0'
printf '\033}tu;555;20;1;0;1\0'
# force render
printf '\033}tr\0'
# assert selection is
printf '\033}tsresults\0'
# remove selection
printf '\033}td;0;0;1;0;0\0\033}tu;0;0;1;0;0\0'
printf '\033}tc;0;0\0\033}tc;1;0\0'
## Select first word: "Insanity"
# There was a bug where only the part of the word on the left of the mouse
# cursor was selected
# double-click to select word
printf '\033}td;40;20;1;0;0\0'
printf '\033}tu;40;20;1;0;0\0'
printf '\033}td;40;20;1;0;1\0'
printf '\033}tu;40;20;1;0;1\0'
# force render
printf '\033}tr\0'
# assert selection is
printf '\033}tsInsanity\0'
# remove selection
printf '\033}td;0;0;1;0;0\0\033}tu;0;0;1;0;0\0'
printf '\033}tc;0;0\0\033}tc;1;0\0'
# Now with a line before
# move to 1,0
printf '\033[1H'
# insert line
printf 'Quote:'
# double-click to select word
printf '\033}td;10;20;1;0;0\0'
printf '\033}tu;10;20;1;0;0\0'
printf '\033}td;10;20;1;0;1\0'
printf '\033}tu;10;20;1;0;1\0'
# force render
printf '\033}tr\0'
# assert selection is
printf '\033}tsInsanity\0'
# remove selection
printf '\033}td;0;0;1;0;0\0\033}tu;0;0;1;0;0\0'
printf '\033}tc;0;0\0\033}tc;1;0\0'

@ -86,6 +86,7 @@ selection_box_all_directions.sh ad1c5bf43f0ec9a921616c3da10cab7f
selection_drag.sh ad1c5bf43f0ec9a921616c3da10cab7f
selection_box_drag.sh ad1c5bf43f0ec9a921616c3da10cab7f
selection_double_click.sh 117cae3dc20237feff08adce1f3c7a2a
selection_word_regression.sh 5d11b208701cc28dc07ca45cf484def9
selection_triple_click.sh 1e7588ca4e6bebee6c0f9af3836974b6
selection_scrolls.sh 3bc69b854a40e1eee64275652f01b827
selection_with_margins_scrolled.sh f3df5d5f2328f12cc8aac254b983306f

Loading…
Cancel
Save