Patch 8.1.0971
Problem: Failure for selecting quoted text object moves cursor.
Solution: Restore the Visual selection on failure. (Christian Brabandt,
closes #4024)
Files: src/search.c, src/testdir/test_textobjects.vim
*** ../vim-8.1.0970/src/search.c 2019-02-17 17:44:36.219875473 +0100
--- src/search.c 2019-02-22 14:55:16.869702567 +0100
***************
*** 4359,4369 ****
int col_end;
int col_start = curwin->w_cursor.col;
int inclusive = FALSE;
! int vis_empty = TRUE; /* Visual selection <= 1 char */
! int vis_bef_curs = FALSE; /* Visual starts before cursor
*/
! int inside_quotes = FALSE; /* Looks like "i'" done before
*/
! int selected_quote = FALSE; /* Has quote inside selection */
int i;
/* Correct cursor when 'selection' is "exclusive". */
if (VIsual_active)
--- 4359,4370 ----
int col_end;
int col_start = curwin->w_cursor.col;
int inclusive = FALSE;
! int vis_empty = TRUE; // Visual selection <= 1 char
! int vis_bef_curs = FALSE; // Visual starts before cursor
! int inside_quotes = FALSE; // Looks like "i'" done before
! int selected_quote = FALSE; // Has quote inside selection
int i;
+ int restore_vis_bef = FALSE; // restore VIsual on abort
/* Correct cursor when 'selection' is "exclusive". */
if (VIsual_active)
***************
*** 4377,4388 ****
{
if (!vis_bef_curs)
{
! /* VIsual needs to be start of Visual selection. */
pos_T t = curwin->w_cursor;
curwin->w_cursor = VIsual;
VIsual = t;
vis_bef_curs = TRUE;
}
dec_cursor();
}
--- 4378,4390 ----
{
if (!vis_bef_curs)
{
! // VIsual needs to be the start of Visual selection.
pos_T t = curwin->w_cursor;
curwin->w_cursor = VIsual;
VIsual = t;
vis_bef_curs = TRUE;
+ restore_vis_bef = TRUE;
}
dec_cursor();
}
***************
*** 4431,4437 ****
* opening quote. */
col_start = find_next_quote(line, col_start + 1, quotechar, NULL);
if (col_start < 0)
! return FALSE;
col_end = find_next_quote(line, col_start + 1, quotechar,
curbuf->b_p_qe);
if (col_end < 0)
--- 4433,4439 ----
* opening quote. */
col_start = find_next_quote(line, col_start + 1, quotechar, NULL);
if (col_start < 0)
! goto abort_search;
col_end = find_next_quote(line, col_start + 1, quotechar,
curbuf->b_p_qe);
if (col_end < 0)
***************
*** 4445,4451 ****
{
col_end = find_prev_quote(line, col_start, quotechar, NULL);
if (line[col_end] != quotechar)
! return FALSE;
col_start = find_prev_quote(line, col_end, quotechar,
curbuf->b_p_qe);
if (line[col_start] != quotechar)
--- 4447,4453 ----
{
col_end = find_prev_quote(line, col_start, quotechar, NULL);
if (line[col_end] != quotechar)
! goto abort_search;
col_start = find_prev_quote(line, col_end, quotechar,
curbuf->b_p_qe);
if (line[col_start] != quotechar)
***************
*** 4480,4491 ****
/* Find open quote character. */
col_start = find_next_quote(line, col_start, quotechar, NULL);
if (col_start < 0 || col_start > first_col)
! return FALSE;
/* Find close quote character. */
col_end = find_next_quote(line, col_start + 1, quotechar,
curbuf->b_p_qe);
if (col_end < 0)
! return FALSE;
/* If is cursor between start and end quote character, it is
* target text object. */
if (col_start <= first_col && first_col <= col_end)
--- 4482,4493 ----
/* Find open quote character. */
col_start = find_next_quote(line, col_start, quotechar, NULL);
if (col_start < 0 || col_start > first_col)
! goto abort_search;
/* Find close quote character. */
col_end = find_next_quote(line, col_start + 1, quotechar,
curbuf->b_p_qe);
if (col_end < 0)
! goto abort_search;
/* If is cursor between start and end quote character, it is
* target text object. */
if (col_start <= first_col && first_col <= col_end)
***************
*** 4502,4515 ****
/* No quote before the cursor, look after the cursor. */
col_start = find_next_quote(line, col_start, quotechar, NULL);
if (col_start < 0)
! return FALSE;
}
/* Find close quote character. */
col_end = find_next_quote(line, col_start + 1, quotechar,
curbuf->b_p_qe);
if (col_end < 0)
! return FALSE;
}
/* When "include" is TRUE, include spaces after closing quote or before
--- 4504,4517 ----
/* No quote before the cursor, look after the cursor. */
col_start = find_next_quote(line, col_start, quotechar, NULL);
if (col_start < 0)
! goto abort_search;
}
/* Find close quote character. */
col_end = find_next_quote(line, col_start + 1, quotechar,
curbuf->b_p_qe);
if (col_end < 0)
! goto abort_search;
}
/* When "include" is TRUE, include spaces after closing quote or before
***************
*** 4596,4601 ****
--- 4598,4617 ----
}
return OK;
+
+ abort_search:
+ if (VIsual_active && *p_sel == 'e')
+ {
+ inc_cursor();
+ if (restore_vis_bef)
+ {
+ pos_T t = curwin->w_cursor;
+
+ curwin->w_cursor = VIsual;
+ VIsual = t;
+ }
+ }
+ return FALSE;
}
#endif /* FEAT_TEXTOBJ */
*** ../vim-8.1.0970/src/testdir/test_textobjects.vim 2019-01-09
23:00:58.001176090 +0100
--- src/testdir/test_textobjects.vim 2019-02-22 14:56:31.897291834 +0100
***************
*** 52,57 ****
--- 52,82 ----
bw!
endfunc
+ func Test_quote_selection_selection_exclusive_abort()
+ new
+ set selection=exclusive
+ call setline(1, "'abzzc'")
+ let exp_curs = [0, 1, 6, 0]
+ call cursor(1,1)
+ exe 'norm! fcdvi"'
+ " make sure to end visual mode to have a clear state
+ exe "norm! \<esc>"
+ call assert_equal(exp_curs, getpos('.'))
+ call cursor(1,1)
+ exe 'norm! fcvi"'
+ exe "norm! \<esc>"
+ call assert_equal(exp_curs, getpos('.'))
+ call cursor(1,2)
+ exe 'norm! vfcoi"'
+ exe "norm! \<esc>"
+ let exp_curs = [0, 1, 2, 0]
+ let exp_visu = [0, 1, 7, 0]
+ call assert_equal(exp_curs, getpos('.'))
+ call assert_equal(exp_visu, getpos("'>"))
+ set selection&vim
+ bw!
+ endfunc
+
" Tests for string and html text objects
func Test_string_html_objects()
enew!
*** ../vim-8.1.0970/src/version.c 2019-02-22 14:38:46.447452832 +0100
--- src/version.c 2019-02-22 15:02:30.395260732 +0100
***************
*** 781,782 ****
--- 781,784 ----
{ /* Add new patch number below this line */
+ /**/
+ 971,
/**/
--
hundred-and-one symptoms of being an internet addict:
11. You find yourself typing "com" after every period when using a word
processor.com
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.