comparison src/normal.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 33ca088dbd3e
children dcde141f2d1e
comparison
equal deleted inserted replaced
31132:f56004c00be2 31133:cc0c4141fb73
1928 cursor_correct(); 1928 cursor_correct();
1929 curwin->w_redr_status = TRUE; 1929 curwin->w_redr_status = TRUE;
1930 } 1930 }
1931 1931
1932 // do the horizontal scroll 1932 // do the horizontal scroll
1933 if (want_hor && curwin->w_leftcol != tgt_leftcol) 1933 if (want_hor)
1934 { 1934 (void)set_leftcol(tgt_leftcol);
1935 curwin->w_leftcol = tgt_leftcol;
1936 leftcol_changed();
1937 }
1938 } 1935 }
1939 1936
1940 // reset current-window 1937 // reset current-window
1941 VIsual_select = old_VIsual_select; 1938 VIsual_select = old_VIsual_select;
1942 VIsual_active = old_VIsual_active; 1939 VIsual_active = old_VIsual_active;
2456 2453
2457 if (up) 2454 if (up)
2458 scrollup(count, TRUE); 2455 scrollup(count, TRUE);
2459 else 2456 else
2460 scrolldown(count, TRUE); 2457 scrolldown(count, TRUE);
2461 if (get_scrolloff_value()) 2458 if (get_scrolloff_value() > 0)
2462 { 2459 {
2463 // Adjust the cursor position for 'scrolloff'. Mark w_topline as 2460 // Adjust the cursor position for 'scrolloff'. Mark w_topline as
2464 // valid, otherwise the screen jumps back at the end of the file. 2461 // valid, otherwise the screen jumps back at the end of the file.
2465 cursor_correct(); 2462 cursor_correct();
2466 check_cursor_moved(curwin); 2463 check_cursor_moved(curwin);
2732 2729
2733 // "zh" - scroll screen to the right 2730 // "zh" - scroll screen to the right
2734 case 'h': 2731 case 'h':
2735 case K_LEFT: 2732 case K_LEFT:
2736 if (!curwin->w_p_wrap) 2733 if (!curwin->w_p_wrap)
2737 { 2734 (void)set_leftcol((colnr_T)cap->count1 > curwin->w_leftcol
2738 if ((colnr_T)cap->count1 > curwin->w_leftcol) 2735 ? 0 : curwin->w_leftcol - (colnr_T)cap->count1);
2739 curwin->w_leftcol = 0;
2740 else
2741 curwin->w_leftcol -= (colnr_T)cap->count1;
2742 leftcol_changed();
2743 }
2744 break; 2736 break;
2745 2737
2746 // "zL" - scroll screen left half-page 2738 // "zL" - scroll window left half-page
2747 case 'L': cap->count1 *= curwin->w_width / 2; 2739 case 'L': cap->count1 *= curwin->w_width / 2;
2748 // FALLTHROUGH 2740 // FALLTHROUGH
2749 2741
2750 // "zl" - scroll screen to the left 2742 // "zl" - scroll window to the left if not wrapping
2751 case 'l': 2743 case 'l':
2752 case K_RIGHT: 2744 case K_RIGHT:
2753 if (!curwin->w_p_wrap) 2745 if (!curwin->w_p_wrap)
2754 { 2746 (void)set_leftcol(curwin->w_leftcol + (colnr_T)cap->count1);
2755 // scroll the window left
2756 curwin->w_leftcol += (colnr_T)cap->count1;
2757 leftcol_changed();
2758 }
2759 break; 2747 break;
2760 2748
2761 // "zs" - scroll screen, cursor at the start 2749 // "zs" - scroll screen, cursor at the start
2762 case 's': if (!curwin->w_p_wrap) 2750 case 's': if (!curwin->w_p_wrap)
2763 { 2751 {