Mercurial > vim
comparison src/ops.c @ 6927:58d9f967ae1a v7.4.782
patch 7.4.782
Problem: Still a few problems with CTRL-A and CTRL-X in Visual mode.
Solution: Fix the reported problems. (Christian Brabandt)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Fri, 17 Jul 2015 13:03:48 +0200 |
parents | 9a13e3910e3d |
children | e55929fca0cf |
comparison
equal
deleted
inserted
replaced
6926:b2839b524d9f | 6927:58d9f967ae1a |
---|---|
5403 int i; | 5403 int i; |
5404 int lnum = curwin->w_cursor.lnum; | 5404 int lnum = curwin->w_cursor.lnum; |
5405 int lnume = curwin->w_cursor.lnum; | 5405 int lnume = curwin->w_cursor.lnum; |
5406 int startcol = 0; | 5406 int startcol = 0; |
5407 int did_change = FALSE; | 5407 int did_change = FALSE; |
5408 pos_T t = curwin->w_cursor; | |
5409 int maxlen = 0; | |
5408 | 5410 |
5409 dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */ | 5411 dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */ |
5410 dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); /* "Octal" */ | 5412 dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); /* "Octal" */ |
5411 doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */ | 5413 doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */ |
5412 | 5414 |
5416 col = curwin->w_cursor.col; | 5418 col = curwin->w_cursor.col; |
5417 if (VIsual_active) | 5419 if (VIsual_active) |
5418 { | 5420 { |
5419 if (lt(curwin->w_cursor, VIsual)) | 5421 if (lt(curwin->w_cursor, VIsual)) |
5420 { | 5422 { |
5421 pos_T t; | |
5422 t = curwin->w_cursor; | |
5423 curwin->w_cursor = VIsual; | 5423 curwin->w_cursor = VIsual; |
5424 VIsual = t; | 5424 VIsual = t; |
5425 } | 5425 } |
5426 if (VIsual_mode == 'V') | |
5427 VIsual.col = 0; | |
5428 | 5426 |
5429 ptr = ml_get(VIsual.lnum); | 5427 ptr = ml_get(VIsual.lnum); |
5430 RLADDSUBFIX(ptr); | 5428 RLADDSUBFIX(ptr); |
5429 if (VIsual_mode == 'V') | |
5430 { | |
5431 VIsual.col = 0; | |
5432 curwin->w_cursor.col = STRLEN(ptr); | |
5433 } | |
5434 else if (VIsual_mode == Ctrl_V && | |
5435 VIsual.col > curwin->w_cursor.col) | |
5436 { | |
5437 t = VIsual; | |
5438 VIsual.col = curwin->w_cursor.col; | |
5439 curwin->w_cursor.col = t.col; | |
5440 } | |
5431 | 5441 |
5432 /* store visual area for 'gv' */ | 5442 /* store visual area for 'gv' */ |
5433 curbuf->b_visual.vi_start = VIsual; | 5443 curbuf->b_visual.vi_start = VIsual; |
5434 curbuf->b_visual.vi_end = curwin->w_cursor; | 5444 curbuf->b_visual.vi_end = curwin->w_cursor; |
5435 curbuf->b_visual.vi_mode = VIsual_mode; | 5445 curbuf->b_visual.vi_mode = VIsual_mode; |
5446 curbuf->b_visual.vi_curswant = curwin->w_curswant; | |
5436 | 5447 |
5437 if (VIsual_mode != 'v') | 5448 if (VIsual_mode != 'v') |
5438 startcol = VIsual.col < curwin->w_cursor.col ? VIsual.col | 5449 startcol = VIsual.col < curwin->w_cursor.col ? VIsual.col |
5439 : curwin->w_cursor.col; | 5450 : curwin->w_cursor.col; |
5440 else | 5451 else |
5480 } | 5491 } |
5481 } | 5492 } |
5482 | 5493 |
5483 for (i = lnum; i <= lnume; i++) | 5494 for (i = lnum; i <= lnume; i++) |
5484 { | 5495 { |
5496 t = curwin->w_cursor; | |
5485 curwin->w_cursor.lnum = i; | 5497 curwin->w_cursor.lnum = i; |
5486 ptr = ml_get_curline(); | 5498 ptr = ml_get_curline(); |
5499 RLADDSUBFIX(ptr); | |
5487 if ((int)STRLEN(ptr) <= col) | 5500 if ((int)STRLEN(ptr) <= col) |
5488 /* try again on next line */ | 5501 /* try again on next line */ |
5489 continue; | 5502 continue; |
5503 if (visual) | |
5504 { | |
5505 if (doalp) /* search for ascii chars */ | |
5506 { | |
5507 while (!ASCII_ISALPHA(ptr[col]) && ptr[col]) | |
5508 col++; | |
5509 } | |
5510 /* skip to first digit, but allow for leading '-' */ | |
5511 else if (dohex) | |
5512 { | |
5513 while (!(vim_isxdigit(ptr[col]) || (ptr[col] == '-' | |
5514 && vim_isxdigit(ptr[col+1]))) && ptr[col]) | |
5515 col++; | |
5516 } | |
5517 else /* decimal */ | |
5518 { | |
5519 while (!(vim_isdigit(ptr[col]) || (ptr[col] == '-' | |
5520 && vim_isdigit(ptr[col+1]))) && ptr[col]) | |
5521 col++; | |
5522 } | |
5523 } | |
5490 if (visual && ptr[col] == '-') | 5524 if (visual && ptr[col] == '-') |
5491 { | 5525 { |
5492 negative = TRUE; | 5526 negative = TRUE; |
5493 was_positive = FALSE; | 5527 was_positive = FALSE; |
5494 col++; | 5528 col++; |
5495 } | 5529 } |
5496 RLADDSUBFIX(ptr); | |
5497 /* | 5530 /* |
5498 * If a number was found, and saving for undo works, replace the number. | 5531 * If a number was found, and saving for undo works, replace the number. |
5499 */ | 5532 */ |
5500 firstdigit = ptr[col]; | 5533 firstdigit = ptr[col]; |
5501 RLADDSUBFIX(ptr); | |
5502 if ((!VIM_ISDIGIT(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit))) | 5534 if ((!VIM_ISDIGIT(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit))) |
5503 || u_save_cursor() != OK) | 5535 || u_save_cursor() != OK) |
5504 { | 5536 { |
5505 if (lnum < lnume) | 5537 if (lnum < lnume) |
5538 { | |
5539 if (visual && VIsual_mode != Ctrl_V) | |
5540 col = 0; | |
5541 else | |
5542 col = startcol; | |
5506 /* Try again on next line */ | 5543 /* Try again on next line */ |
5507 continue; | 5544 continue; |
5545 } | |
5508 beep_flush(); | 5546 beep_flush(); |
5509 return FAIL; | 5547 return FAIL; |
5510 } | 5548 } |
5511 | |
5512 ptr = ml_get_curline(); | |
5513 RLADDSUBFIX(ptr); | |
5514 | 5549 |
5515 if (doalp && ASCII_ISALPHA(firstdigit)) | 5550 if (doalp && ASCII_ISALPHA(firstdigit)) |
5516 { | 5551 { |
5517 /* decrement or increment alphabetic character */ | 5552 /* decrement or increment alphabetic character */ |
5518 if (command == Ctrl_X) | 5553 if (command == Ctrl_X) |
5558 { | 5593 { |
5559 /* negative number */ | 5594 /* negative number */ |
5560 --col; | 5595 --col; |
5561 negative = TRUE; | 5596 negative = TRUE; |
5562 } | 5597 } |
5563 | |
5564 /* get the number value (unsigned) */ | 5598 /* get the number value (unsigned) */ |
5565 vim_str2nr(ptr + col, &hex, &length, dooct, dohex, NULL, &n); | 5599 if (visual && VIsual_mode != 'V') |
5600 { | |
5601 if (VIsual_mode == 'v') | |
5602 { | |
5603 if (i == lnum) | |
5604 maxlen = (lnum == lnume | |
5605 ? curwin->w_cursor.col - col + 1 | |
5606 : (int)STRLEN(ptr) - col); | |
5607 else | |
5608 maxlen = (i == lnume ? curwin->w_cursor.col - col + 1 | |
5609 : (int)STRLEN(ptr) - col); | |
5610 } | |
5611 else if (VIsual_mode == Ctrl_V) | |
5612 maxlen = (curbuf->b_visual.vi_curswant == MAXCOL | |
5613 ? (int)STRLEN(ptr) - col | |
5614 : curwin->w_cursor.col - col + 1); | |
5615 } | |
5616 | |
5617 vim_str2nr(ptr + col, &hex, &length, dooct, dohex, NULL, &n, | |
5618 maxlen); | |
5566 | 5619 |
5567 /* ignore leading '-' for hex and octal numbers */ | 5620 /* ignore leading '-' for hex and octal numbers */ |
5568 if (hex && negative) | 5621 if (hex && negative) |
5569 { | 5622 { |
5570 ++col; | 5623 ++col; |
5607 } | 5660 } |
5608 if (n == 0) | 5661 if (n == 0) |
5609 negative = FALSE; | 5662 negative = FALSE; |
5610 } | 5663 } |
5611 | 5664 |
5612 if (visual && !was_positive && !negative) | 5665 if (visual && !was_positive && !negative && col > 0) |
5613 { | 5666 { |
5614 /* need to remove the '-' */ | 5667 /* need to remove the '-' */ |
5615 col--; | 5668 col--; |
5616 length++; | 5669 length++; |
5617 } | 5670 } |
5693 *ptr++ = '0'; | 5746 *ptr++ = '0'; |
5694 *ptr = NUL; | 5747 *ptr = NUL; |
5695 STRCAT(buf1, buf2); | 5748 STRCAT(buf1, buf2); |
5696 ins_str(buf1); /* insert the new number */ | 5749 ins_str(buf1); /* insert the new number */ |
5697 vim_free(buf1); | 5750 vim_free(buf1); |
5751 if (lnum < lnume) | |
5752 curwin->w_cursor.col = t.col; | |
5753 else if (did_change && curwin->w_cursor.col) | |
5754 --curwin->w_cursor.col; | |
5698 } | 5755 } |
5699 | 5756 |
5700 if (g_cmd) | 5757 if (g_cmd) |
5701 { | 5758 { |
5702 offset = (unsigned long)Prenum1; | 5759 offset = (unsigned long)Prenum1; |
5703 g_cmd = 0; | 5760 g_cmd = 0; |
5704 } | 5761 } |
5705 /* reset */ | 5762 /* reset */ |
5706 subtract = FALSE; | 5763 subtract = FALSE; |
5707 negative = FALSE; | 5764 negative = FALSE; |
5765 was_positive = TRUE; | |
5708 if (visual && VIsual_mode == Ctrl_V) | 5766 if (visual && VIsual_mode == Ctrl_V) |
5709 col = startcol; | 5767 col = startcol; |
5710 else | 5768 else |
5711 col = 0; | 5769 col = 0; |
5712 Prenum1 += offset; | 5770 Prenum1 += offset; |
5714 #ifdef FEAT_RIGHTLEFT | 5772 #ifdef FEAT_RIGHTLEFT |
5715 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); | 5773 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); |
5716 RLADDSUBFIX(ptr); | 5774 RLADDSUBFIX(ptr); |
5717 #endif | 5775 #endif |
5718 } | 5776 } |
5719 if (did_change && curwin->w_cursor.col > 0) | 5777 if (visual) |
5720 --curwin->w_cursor.col; | 5778 /* cursor at the top of the selection */ |
5779 curwin->w_cursor = VIsual; | |
5721 return OK; | 5780 return OK; |
5722 } | 5781 } |
5723 | 5782 |
5724 #ifdef FEAT_VIMINFO | 5783 #ifdef FEAT_VIMINFO |
5725 int | 5784 int |