summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-06-19 18:27:41 +0200
committerBram Moolenaar <Bram@vim.org>2018-06-19 18:27:41 +0200
commit8516071124dbb7ad7caa43cc98ae3c57ae093c9e (patch)
tree968387c224ff5fba447299c97f0f36542b612a7f
parent1d4754f96fa5bff1c349cdb71560c55675f50d03 (diff)
patch 8.1.0083: "is" and "as" have trouble with quoted punctuationv8.1.0083
Problem: "is" and "as" have trouble with quoted punctuation. Solution: Check for punctuation before a quote. (Jason Franklin)
-rw-r--r--src/search.c40
-rw-r--r--src/testdir/test_textobjects.vim75
-rw-r--r--src/version.c2
3 files changed, 97 insertions, 20 deletions
diff --git a/src/search.c b/src/search.c
index 57434ec0b7..66ae647185 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2707,10 +2707,11 @@ showmatch(
}
/*
- * findsent(dir, count) - Find the start of the next sentence in direction
- * "dir" Sentences are supposed to end in ".", "!" or "?" followed by white
- * space or a line break. Also stop at an empty line.
- * Return OK if the next sentence was found.
+ * Find the start of the next sentence, searching in the direction specified
+ * by the "dir" argument. The cursor is positioned on the start of the next
+ * sentence when found. If the next sentence is found, return OK. Return FAIL
+ * otherwise. See ":h sentence" for the precise definition of a "sentence"
+ * text object.
*/
int
findsent(int dir, long count)
@@ -2758,26 +2759,25 @@ findsent(int dir, long count)
else if (dir == BACKWARD)
decl(&pos);
- /* go back to the previous non-blank char */
+ // go back to the previous non-white non-punctuation character
found_dot = FALSE;
- while ((c = gchar_pos(&pos)) == ' ' || c == '\t' ||
- (dir == BACKWARD && vim_strchr((char_u *)".!?)]\"'", c) != NULL))
+ while (c = gchar_pos(&pos), VIM_ISWHITE(c)
+ || vim_strchr((char_u *)".!?)]\"'", c) != NULL)
{
- if (vim_strchr((char_u *)".!?", c) != NULL)
- {
- /* Only skip over a '.', '!' and '?' once. */
- if (found_dot)
- break;
+ tpos = pos;
+ if (decl(&tpos) == -1 || (LINEEMPTY(tpos.lnum) && dir == FORWARD))
+ break;
+
+ if (found_dot)
+ break;
+ if (vim_strchr((char_u *) ".!?", c) != NULL)
found_dot = TRUE;
- }
- if (decl(&pos) == -1)
+
+ if (vim_strchr((char_u *) ")]\"'", c) != NULL
+ && vim_strchr((char_u *) ".!?)]\"'", gchar_pos(&tpos)) == NULL)
break;
- /* when going forward: Stop in front of empty line */
- if (LINEEMPTY(pos.lnum) && dir == FORWARD)
- {
- incl(&pos);
- goto found;
- }
+
+ decl(&pos);
}
/* remember the line where the search started */
diff --git a/src/testdir/test_textobjects.vim b/src/testdir/test_textobjects.vim
index 17602fbe26..f02619fc09 100644
--- a/src/testdir/test_textobjects.vim
+++ b/src/testdir/test_textobjects.vim
@@ -165,3 +165,78 @@ x
norm it
q!
endfunc
+
+func Test_sentence()
+ enew!
+ call setline(1, 'A sentence. A sentence? A sentence!')
+
+ normal yis
+ call assert_equal('A sentence.', @")
+ normal yas
+ call assert_equal('A sentence. ', @")
+
+ normal )
+
+ normal yis
+ call assert_equal('A sentence?', @")
+ normal yas
+ call assert_equal('A sentence? ', @")
+
+ normal )
+
+ normal yis
+ call assert_equal('A sentence!', @")
+ normal yas
+ call assert_equal(' A sentence!', @")
+
+ normal 0
+ normal 2yis
+ call assert_equal('A sentence. ', @")
+ normal 3yis
+ call assert_equal('A sentence. A sentence?', @")
+ normal 2yas
+ call assert_equal('A sentence. A sentence? ', @")
+
+ %delete _
+endfunc
+
+func Test_sentence_with_quotes()
+ enew!
+ call setline(1, 'A "sentence." A sentence.')
+
+ normal yis
+ call assert_equal('A "sentence."', @")
+ normal yas
+ call assert_equal('A "sentence." ', @")
+
+ normal )
+
+ normal yis
+ call assert_equal('A sentence.', @")
+ normal yas
+ call assert_equal(' A sentence.', @")
+
+ %delete _
+endfunc
+
+func! Test_sentence_with_cursor_on_delimiter()
+ enew!
+ call setline(1, "A '([sentence.])' A sentence.")
+
+ normal! 15|yis
+ call assert_equal("A '([sentence.])'", @")
+ normal! 15|yas
+ call assert_equal("A '([sentence.])' ", @")
+
+ normal! 16|yis
+ call assert_equal("A '([sentence.])'", @")
+ normal! 16|yas
+ call assert_equal("A '([sentence.])' ", @")
+
+ normal! 17|yis
+ call assert_equal("A '([sentence.])'", @")
+ normal! 17|yas
+ call assert_equal("A '([sentence.])' ", @")
+
+ %delete _
+endfunc
diff --git a/src/version.c b/src/version.c
index 1cdc8d4eee..20cd3803cd 100644
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 83,
+/**/
82,
/**/
81,