Mercurial > vim
comparison src/search.c @ 15930:e580c9d75443 v8.1.0971
patch 8.1.0971: failure for selecting quoted text object moves cursor
commit https://github.com/vim/vim/commit/55d3bdbbe2bfc7a78b4aa17763788dbddf87cab0
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Feb 22 15:04:17 2019 +0100
patch 8.1.0971: failure for selecting quoted text object moves cursor
Problem: Failure for selecting quoted text object moves cursor.
Solution: Restore the Visual selection on failure. (Christian Brabandt,
closes #4024)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 22 Feb 2019 15:15:05 +0100 |
parents | 7fad90423bd2 |
children | ced614446eaa |
comparison
equal
deleted
inserted
replaced
15929:b6a90f793191 | 15930:e580c9d75443 |
---|---|
4357 { | 4357 { |
4358 char_u *line = ml_get_curline(); | 4358 char_u *line = ml_get_curline(); |
4359 int col_end; | 4359 int col_end; |
4360 int col_start = curwin->w_cursor.col; | 4360 int col_start = curwin->w_cursor.col; |
4361 int inclusive = FALSE; | 4361 int inclusive = FALSE; |
4362 int vis_empty = TRUE; /* Visual selection <= 1 char */ | 4362 int vis_empty = TRUE; // Visual selection <= 1 char |
4363 int vis_bef_curs = FALSE; /* Visual starts before cursor */ | 4363 int vis_bef_curs = FALSE; // Visual starts before cursor |
4364 int inside_quotes = FALSE; /* Looks like "i'" done before */ | 4364 int inside_quotes = FALSE; // Looks like "i'" done before |
4365 int selected_quote = FALSE; /* Has quote inside selection */ | 4365 int selected_quote = FALSE; // Has quote inside selection |
4366 int i; | 4366 int i; |
4367 int restore_vis_bef = FALSE; // restore VIsual on abort | |
4367 | 4368 |
4368 /* Correct cursor when 'selection' is "exclusive". */ | 4369 /* Correct cursor when 'selection' is "exclusive". */ |
4369 if (VIsual_active) | 4370 if (VIsual_active) |
4370 { | 4371 { |
4371 /* this only works within one line */ | 4372 /* this only works within one line */ |
4375 vis_bef_curs = LT_POS(VIsual, curwin->w_cursor); | 4376 vis_bef_curs = LT_POS(VIsual, curwin->w_cursor); |
4376 if (*p_sel == 'e') | 4377 if (*p_sel == 'e') |
4377 { | 4378 { |
4378 if (!vis_bef_curs) | 4379 if (!vis_bef_curs) |
4379 { | 4380 { |
4380 /* VIsual needs to be start of Visual selection. */ | 4381 // VIsual needs to be the start of Visual selection. |
4381 pos_T t = curwin->w_cursor; | 4382 pos_T t = curwin->w_cursor; |
4382 | 4383 |
4383 curwin->w_cursor = VIsual; | 4384 curwin->w_cursor = VIsual; |
4384 VIsual = t; | 4385 VIsual = t; |
4385 vis_bef_curs = TRUE; | 4386 vis_bef_curs = TRUE; |
4387 restore_vis_bef = TRUE; | |
4386 } | 4388 } |
4387 dec_cursor(); | 4389 dec_cursor(); |
4388 } | 4390 } |
4389 vis_empty = EQUAL_POS(VIsual, curwin->w_cursor); | 4391 vis_empty = EQUAL_POS(VIsual, curwin->w_cursor); |
4390 } | 4392 } |
4429 { | 4431 { |
4430 /* Assume we are on a closing quote: move to after the next | 4432 /* Assume we are on a closing quote: move to after the next |
4431 * opening quote. */ | 4433 * opening quote. */ |
4432 col_start = find_next_quote(line, col_start + 1, quotechar, NULL); | 4434 col_start = find_next_quote(line, col_start + 1, quotechar, NULL); |
4433 if (col_start < 0) | 4435 if (col_start < 0) |
4434 return FALSE; | 4436 goto abort_search; |
4435 col_end = find_next_quote(line, col_start + 1, quotechar, | 4437 col_end = find_next_quote(line, col_start + 1, quotechar, |
4436 curbuf->b_p_qe); | 4438 curbuf->b_p_qe); |
4437 if (col_end < 0) | 4439 if (col_end < 0) |
4438 { | 4440 { |
4439 /* We were on a starting quote perhaps? */ | 4441 /* We were on a starting quote perhaps? */ |
4443 } | 4445 } |
4444 else | 4446 else |
4445 { | 4447 { |
4446 col_end = find_prev_quote(line, col_start, quotechar, NULL); | 4448 col_end = find_prev_quote(line, col_start, quotechar, NULL); |
4447 if (line[col_end] != quotechar) | 4449 if (line[col_end] != quotechar) |
4448 return FALSE; | 4450 goto abort_search; |
4449 col_start = find_prev_quote(line, col_end, quotechar, | 4451 col_start = find_prev_quote(line, col_end, quotechar, |
4450 curbuf->b_p_qe); | 4452 curbuf->b_p_qe); |
4451 if (line[col_start] != quotechar) | 4453 if (line[col_start] != quotechar) |
4452 { | 4454 { |
4453 /* We were on an ending quote perhaps? */ | 4455 /* We were on an ending quote perhaps? */ |
4478 for (;;) | 4480 for (;;) |
4479 { | 4481 { |
4480 /* Find open quote character. */ | 4482 /* Find open quote character. */ |
4481 col_start = find_next_quote(line, col_start, quotechar, NULL); | 4483 col_start = find_next_quote(line, col_start, quotechar, NULL); |
4482 if (col_start < 0 || col_start > first_col) | 4484 if (col_start < 0 || col_start > first_col) |
4483 return FALSE; | 4485 goto abort_search; |
4484 /* Find close quote character. */ | 4486 /* Find close quote character. */ |
4485 col_end = find_next_quote(line, col_start + 1, quotechar, | 4487 col_end = find_next_quote(line, col_start + 1, quotechar, |
4486 curbuf->b_p_qe); | 4488 curbuf->b_p_qe); |
4487 if (col_end < 0) | 4489 if (col_end < 0) |
4488 return FALSE; | 4490 goto abort_search; |
4489 /* If is cursor between start and end quote character, it is | 4491 /* If is cursor between start and end quote character, it is |
4490 * target text object. */ | 4492 * target text object. */ |
4491 if (col_start <= first_col && first_col <= col_end) | 4493 if (col_start <= first_col && first_col <= col_end) |
4492 break; | 4494 break; |
4493 col_start = col_end + 1; | 4495 col_start = col_end + 1; |
4500 if (line[col_start] != quotechar) | 4502 if (line[col_start] != quotechar) |
4501 { | 4503 { |
4502 /* No quote before the cursor, look after the cursor. */ | 4504 /* No quote before the cursor, look after the cursor. */ |
4503 col_start = find_next_quote(line, col_start, quotechar, NULL); | 4505 col_start = find_next_quote(line, col_start, quotechar, NULL); |
4504 if (col_start < 0) | 4506 if (col_start < 0) |
4505 return FALSE; | 4507 goto abort_search; |
4506 } | 4508 } |
4507 | 4509 |
4508 /* Find close quote character. */ | 4510 /* Find close quote character. */ |
4509 col_end = find_next_quote(line, col_start + 1, quotechar, | 4511 col_end = find_next_quote(line, col_start + 1, quotechar, |
4510 curbuf->b_p_qe); | 4512 curbuf->b_p_qe); |
4511 if (col_end < 0) | 4513 if (col_end < 0) |
4512 return FALSE; | 4514 goto abort_search; |
4513 } | 4515 } |
4514 | 4516 |
4515 /* When "include" is TRUE, include spaces after closing quote or before | 4517 /* When "include" is TRUE, include spaces after closing quote or before |
4516 * the starting quote. */ | 4518 * the starting quote. */ |
4517 if (include) | 4519 if (include) |
4594 /* Set inclusive and other oap's flags. */ | 4596 /* Set inclusive and other oap's flags. */ |
4595 oap->inclusive = inclusive; | 4597 oap->inclusive = inclusive; |
4596 } | 4598 } |
4597 | 4599 |
4598 return OK; | 4600 return OK; |
4601 | |
4602 abort_search: | |
4603 if (VIsual_active && *p_sel == 'e') | |
4604 { | |
4605 inc_cursor(); | |
4606 if (restore_vis_bef) | |
4607 { | |
4608 pos_T t = curwin->w_cursor; | |
4609 | |
4610 curwin->w_cursor = VIsual; | |
4611 VIsual = t; | |
4612 } | |
4613 } | |
4614 return FALSE; | |
4599 } | 4615 } |
4600 | 4616 |
4601 #endif /* FEAT_TEXTOBJ */ | 4617 #endif /* FEAT_TEXTOBJ */ |
4602 | 4618 |
4603 static int is_one_char(char_u *pattern, int move, pos_T *cur, int direction); | 4619 static int is_one_char(char_u *pattern, int move, pos_T *cur, int direction); |