Mercurial > vim
comparison src/misc2.c @ 31133:cc0c4141fb73 v9.0.0901
patch 9.0.0901: setting w_leftcol and handling side effects is confusing
Commit: https://github.com/vim/vim/commit/0c34d562647f029faca40f7733ccfb7b5377672b
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Nov 18 14:07:20 2022 +0000
patch 9.0.0901: setting w_leftcol and handling side effects is confusing
Problem: Setting w_leftcol and handling side effects is confusing.
Solution: Use a function to set w_leftcol() and handle side effects.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 18 Nov 2022 15:15:04 +0100 |
parents | 004aee2845d2 |
children | 0ecb16d5f86f |
comparison
equal
deleted
inserted
replaced
31132:f56004c00be2 | 31133:cc0c4141fb73 |
---|---|
671 && gchar_cursor() == NUL) | 671 && gchar_cursor() == NUL) |
672 --curwin->w_cursor.col; | 672 --curwin->w_cursor.col; |
673 } | 673 } |
674 | 674 |
675 /* | 675 /* |
676 * When curwin->w_leftcol has changed, adjust the cursor position. | 676 * Set "curwin->w_leftcol" to "leftcol". |
677 * Adjust the cursor position if needed. | |
677 * Return TRUE if the cursor was moved. | 678 * Return TRUE if the cursor was moved. |
678 */ | 679 */ |
679 int | 680 int |
680 leftcol_changed(void) | 681 set_leftcol(colnr_T leftcol) |
681 { | 682 { |
682 long lastcol; | |
683 colnr_T s, e; | |
684 int retval = FALSE; | 683 int retval = FALSE; |
685 long siso = get_sidescrolloff_value(); | 684 |
685 // Return quickly when there is no change. | |
686 if (curwin->w_leftcol == leftcol) | |
687 return FALSE; | |
688 curwin->w_leftcol = leftcol; | |
686 | 689 |
687 changed_cline_bef_curs(); | 690 changed_cline_bef_curs(); |
688 lastcol = curwin->w_leftcol + curwin->w_width - curwin_col_off() - 1; | 691 long lastcol = curwin->w_leftcol + curwin->w_width - curwin_col_off() - 1; |
689 validate_virtcol(); | 692 validate_virtcol(); |
690 | 693 |
691 /* | 694 // If the cursor is right or left of the screen, move it to last or first |
692 * If the cursor is right or left of the screen, move it to last or first | 695 // visible character. |
693 * character. | 696 long siso = get_sidescrolloff_value(); |
694 */ | |
695 if (curwin->w_virtcol > (colnr_T)(lastcol - siso)) | 697 if (curwin->w_virtcol > (colnr_T)(lastcol - siso)) |
696 { | 698 { |
697 retval = TRUE; | 699 retval = TRUE; |
698 coladvance((colnr_T)(lastcol - siso)); | 700 coladvance((colnr_T)(lastcol - siso)); |
699 } | 701 } |
701 { | 703 { |
702 retval = TRUE; | 704 retval = TRUE; |
703 (void)coladvance((colnr_T)(curwin->w_leftcol + siso)); | 705 (void)coladvance((colnr_T)(curwin->w_leftcol + siso)); |
704 } | 706 } |
705 | 707 |
706 /* | 708 // If the start of the character under the cursor is not on the screen, |
707 * If the start of the character under the cursor is not on the screen, | 709 // advance the cursor one more char. If this fails (last char of the |
708 * advance the cursor one more char. If this fails (last char of the | 710 // line) adjust the scrolling. |
709 * line) adjust the scrolling. | 711 colnr_T s, e; |
710 */ | |
711 getvvcol(curwin, &curwin->w_cursor, &s, NULL, &e); | 712 getvvcol(curwin, &curwin->w_cursor, &s, NULL, &e); |
712 if (e > (colnr_T)lastcol) | 713 if (e > (colnr_T)lastcol) |
713 { | 714 { |
714 retval = TRUE; | 715 retval = TRUE; |
715 coladvance(s - 1); | 716 coladvance(s - 1); |