Mercurial > vim
comparison src/search.c @ 18677:953e83e09e78 v8.1.2330
patch 8.1.2330: vi' does not always work when 'selection' is exclusive
Commit: https://github.com/vim/vim/commit/94d9f4fa65bce6f116cf89bfdabdf5a06509056f
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Nov 21 20:55:26 2019 +0100
patch 8.1.2330: vi' does not always work when 'selection' is exclusive
Problem: vi' does not always work when 'selection' is exclusive.
Solution: Adjust start position.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 21 Nov 2019 21:00:04 +0100 |
parents | 7bfe68b637be |
children | a13370d92f9d |
comparison
equal
deleted
inserted
replaced
18676:fc5d1a4c149c | 18677:953e83e09e78 |
---|---|
4410 */ | 4410 */ |
4411 int | 4411 int |
4412 current_quote( | 4412 current_quote( |
4413 oparg_T *oap, | 4413 oparg_T *oap, |
4414 long count, | 4414 long count, |
4415 int include, /* TRUE == include quote char */ | 4415 int include, // TRUE == include quote char |
4416 int quotechar) /* Quote character */ | 4416 int quotechar) // Quote character |
4417 { | 4417 { |
4418 char_u *line = ml_get_curline(); | 4418 char_u *line = ml_get_curline(); |
4419 int col_end; | 4419 int col_end; |
4420 int col_start = curwin->w_cursor.col; | 4420 int col_start = curwin->w_cursor.col; |
4421 int inclusive = FALSE; | 4421 int inclusive = FALSE; |
4422 int vis_empty = TRUE; // Visual selection <= 1 char | 4422 int vis_empty = TRUE; // Visual selection <= 1 char |
4423 int vis_bef_curs = FALSE; // Visual starts before cursor | 4423 int vis_bef_curs = FALSE; // Visual starts before cursor |
4424 int did_exclusive_adj = FALSE; // adjusted pos for 'selection' | |
4424 int inside_quotes = FALSE; // Looks like "i'" done before | 4425 int inside_quotes = FALSE; // Looks like "i'" done before |
4425 int selected_quote = FALSE; // Has quote inside selection | 4426 int selected_quote = FALSE; // Has quote inside selection |
4426 int i; | 4427 int i; |
4427 int restore_vis_bef = FALSE; // restore VIsual on abort | 4428 int restore_vis_bef = FALSE; // restore VIsual on abort |
4428 | 4429 |
4429 /* Correct cursor when 'selection' is "exclusive". */ | 4430 // When 'selection' is "exclusive" move the cursor to where it would be |
4431 // with 'selection' "inclusive", so that the logic is the same for both. | |
4432 // The cursor then is moved forward after adjusting the area. | |
4430 if (VIsual_active) | 4433 if (VIsual_active) |
4431 { | 4434 { |
4432 /* this only works within one line */ | 4435 /* this only works within one line */ |
4433 if (VIsual.lnum != curwin->w_cursor.lnum) | 4436 if (VIsual.lnum != curwin->w_cursor.lnum) |
4434 return FALSE; | 4437 return FALSE; |
4435 | 4438 |
4436 vis_bef_curs = LT_POS(VIsual, curwin->w_cursor); | 4439 vis_bef_curs = LT_POS(VIsual, curwin->w_cursor); |
4437 vis_empty = EQUAL_POS(VIsual, curwin->w_cursor); | 4440 vis_empty = EQUAL_POS(VIsual, curwin->w_cursor); |
4438 if (*p_sel == 'e') | 4441 if (*p_sel == 'e') |
4439 { | 4442 { |
4443 if (vis_bef_curs) | |
4444 { | |
4445 dec_cursor(); | |
4446 did_exclusive_adj = TRUE; | |
4447 } | |
4448 else if (!vis_empty) | |
4449 { | |
4450 dec(&VIsual); | |
4451 did_exclusive_adj = TRUE; | |
4452 } | |
4453 vis_empty = EQUAL_POS(VIsual, curwin->w_cursor); | |
4440 if (!vis_bef_curs && !vis_empty) | 4454 if (!vis_bef_curs && !vis_empty) |
4441 { | 4455 { |
4442 // VIsual needs to be the start of Visual selection. | 4456 // VIsual needs to be the start of Visual selection. |
4443 pos_T t = curwin->w_cursor; | 4457 pos_T t = curwin->w_cursor; |
4444 | 4458 |
4445 curwin->w_cursor = VIsual; | 4459 curwin->w_cursor = VIsual; |
4446 VIsual = t; | 4460 VIsual = t; |
4447 vis_bef_curs = TRUE; | 4461 vis_bef_curs = TRUE; |
4448 restore_vis_bef = TRUE; | 4462 restore_vis_bef = TRUE; |
4449 } | 4463 } |
4450 dec_cursor(); | |
4451 vis_empty = EQUAL_POS(VIsual, curwin->w_cursor); | |
4452 } | 4464 } |
4453 } | 4465 } |
4454 | 4466 |
4455 if (!vis_empty) | 4467 if (!vis_empty) |
4456 { | 4468 { |
4624 inclusive = TRUE; | 4636 inclusive = TRUE; |
4625 if (VIsual_active) | 4637 if (VIsual_active) |
4626 { | 4638 { |
4627 if (vis_empty || vis_bef_curs) | 4639 if (vis_empty || vis_bef_curs) |
4628 { | 4640 { |
4629 /* decrement cursor when 'selection' is not exclusive */ | 4641 // decrement cursor when 'selection' is not exclusive |
4630 if (*p_sel != 'e') | 4642 if (*p_sel != 'e') |
4631 dec_cursor(); | 4643 dec_cursor(); |
4632 } | 4644 } |
4633 else | 4645 else |
4634 { | 4646 { |
4661 return OK; | 4673 return OK; |
4662 | 4674 |
4663 abort_search: | 4675 abort_search: |
4664 if (VIsual_active && *p_sel == 'e') | 4676 if (VIsual_active && *p_sel == 'e') |
4665 { | 4677 { |
4666 inc_cursor(); | 4678 if (did_exclusive_adj) |
4679 inc_cursor(); | |
4667 if (restore_vis_bef) | 4680 if (restore_vis_bef) |
4668 { | 4681 { |
4669 pos_T t = curwin->w_cursor; | 4682 pos_T t = curwin->w_cursor; |
4670 | 4683 |
4671 curwin->w_cursor = VIsual; | 4684 curwin->w_cursor = VIsual; |