comparison src/move.c @ 31728:238ca27dbfd2 v9.0.1196

patch 9.0.1196: code is indented more than necessary Commit: https://github.com/vim/vim/commit/e8575988969579f9e1439181ae338b2ff74054a8 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Jan 14 12:32:28 2023 +0000 patch 9.0.1196: code is indented more than necessary Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11813)
author Bram Moolenaar <Bram@vim.org>
date Sat, 14 Jan 2023 13:45:04 +0100
parents 3c21865e8068
children 2a590b4a3fba
comparison
equal deleted inserted replaced
31727:2b50a7f0feec 31728:238ca27dbfd2
242 * Set curwin->s_skipcol to zero and redraw later if needed. 242 * Set curwin->s_skipcol to zero and redraw later if needed.
243 */ 243 */
244 static void 244 static void
245 reset_skipcol(void) 245 reset_skipcol(void)
246 { 246 {
247 if (curwin->w_skipcol != 0) 247 if (curwin->w_skipcol == 0)
248 { 248 return;
249 curwin->w_skipcol = 0; 249
250 250 curwin->w_skipcol = 0;
251 // Should use the least expensive way that displays all that changed. 251
252 // UPD_NOT_VALID is too expensive, UPD_REDRAW_TOP does not redraw 252 // Should use the least expensive way that displays all that changed.
253 // enough when the top line gets another screen line. 253 // UPD_NOT_VALID is too expensive, UPD_REDRAW_TOP does not redraw
254 redraw_later(UPD_SOME_VALID); 254 // enough when the top line gets another screen line.
255 } 255 redraw_later(UPD_SOME_VALID);
256 } 256 }
257 257
258 /* 258 /*
259 * Update curwin->w_topline and redraw if necessary. 259 * Update curwin->w_topline and redraw if necessary.
260 * Used to update the screen before printing a message. 260 * Used to update the screen before printing a message.
978 */ 978 */
979 void 979 void
980 validate_virtcol_win(win_T *wp) 980 validate_virtcol_win(win_T *wp)
981 { 981 {
982 check_cursor_moved(wp); 982 check_cursor_moved(wp);
983 if (!(wp->w_valid & VALID_VIRTCOL)) 983
984 { 984 if (wp->w_valid & VALID_VIRTCOL)
985 return;
986
985 #ifdef FEAT_PROP_POPUP 987 #ifdef FEAT_PROP_POPUP
986 wp->w_virtcol_first_char = 0; 988 wp->w_virtcol_first_char = 0;
987 #endif 989 #endif
988 getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL); 990 getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL);
989 #ifdef FEAT_SYN_HL 991 #ifdef FEAT_SYN_HL
990 redraw_for_cursorcolumn(wp); 992 redraw_for_cursorcolumn(wp);
991 #endif 993 #endif
992 wp->w_valid |= VALID_VIRTCOL; 994 wp->w_valid |= VALID_VIRTCOL;
993 }
994 } 995 }
995 996
996 /* 997 /*
997 * Validate curwin->w_cline_height only. 998 * Validate curwin->w_cline_height only.
998 */ 999 */
999 void 1000 void
1000 validate_cheight(void) 1001 validate_cheight(void)
1001 { 1002 {
1002 check_cursor_moved(curwin); 1003 check_cursor_moved(curwin);
1003 if (!(curwin->w_valid & VALID_CHEIGHT)) 1004
1004 { 1005 if (curwin->w_valid & VALID_CHEIGHT)
1005 #ifdef FEAT_DIFF 1006 return;
1006 if (curwin->w_cursor.lnum == curwin->w_topline) 1007
1007 curwin->w_cline_height = plines_nofill(curwin->w_cursor.lnum) 1008 #ifdef FEAT_DIFF
1008 + curwin->w_topfill; 1009 if (curwin->w_cursor.lnum == curwin->w_topline)
1009 else 1010 curwin->w_cline_height = plines_nofill(curwin->w_cursor.lnum)
1010 #endif 1011 + curwin->w_topfill;
1011 curwin->w_cline_height = plines(curwin->w_cursor.lnum); 1012 else
1012 #ifdef FEAT_FOLDING 1013 #endif
1013 curwin->w_cline_folded = hasFolding(curwin->w_cursor.lnum, NULL, NULL); 1014 curwin->w_cline_height = plines(curwin->w_cursor.lnum);
1014 #endif 1015 #ifdef FEAT_FOLDING
1015 curwin->w_valid |= VALID_CHEIGHT; 1016 curwin->w_cline_folded = hasFolding(curwin->w_cursor.lnum, NULL, NULL);
1016 } 1017 #endif
1018 curwin->w_valid |= VALID_CHEIGHT;
1017 } 1019 }
1018 1020
1019 /* 1021 /*
1020 * Validate w_wcol and w_virtcol only. 1022 * Validate w_wcol and w_virtcol only.
1021 */ 1023 */
1025 colnr_T off; 1027 colnr_T off;
1026 colnr_T col; 1028 colnr_T col;
1027 int width; 1029 int width;
1028 1030
1029 validate_virtcol(); 1031 validate_virtcol();
1030 if (!(curwin->w_valid & VALID_WCOL)) 1032
1031 { 1033 if (curwin->w_valid & VALID_WCOL)
1032 col = curwin->w_virtcol; 1034 return;
1033 off = curwin_col_off(); 1035
1034 col += off; 1036 col = curwin->w_virtcol;
1035 width = curwin->w_width - off + curwin_col_off2(); 1037 off = curwin_col_off();
1036 1038 col += off;
1037 // long line wrapping, adjust curwin->w_wrow 1039 width = curwin->w_width - off + curwin_col_off2();
1038 if (curwin->w_p_wrap 1040
1039 && col >= (colnr_T)curwin->w_width 1041 // long line wrapping, adjust curwin->w_wrow
1040 && width > 0) 1042 if (curwin->w_p_wrap
1041 // use same formula as what is used in curs_columns() 1043 && col >= (colnr_T)curwin->w_width
1042 col -= ((col - curwin->w_width) / width + 1) * width; 1044 && width > 0)
1043 if (col > (int)curwin->w_leftcol) 1045 // use same formula as what is used in curs_columns()
1044 col -= curwin->w_leftcol; 1046 col -= ((col - curwin->w_width) / width + 1) * width;
1045 else 1047 if (col > (int)curwin->w_leftcol)
1046 col = 0; 1048 col -= curwin->w_leftcol;
1047 curwin->w_wcol = col; 1049 else
1048 1050 col = 0;
1049 curwin->w_valid |= VALID_WCOL; 1051 curwin->w_wcol = col;
1052
1053 curwin->w_valid |= VALID_WCOL;
1050 #ifdef FEAT_PROP_POPUP 1054 #ifdef FEAT_PROP_POPUP
1051 curwin->w_flags &= ~WFLAG_WCOL_OFF_ADDED; 1055 curwin->w_flags &= ~WFLAG_WCOL_OFF_ADDED;
1052 #endif 1056 #endif
1053 }
1054 } 1057 }
1055 1058
1056 /* 1059 /*
1057 * Compute offset of a window, occupied by absolute or relative line number, 1060 * Compute offset of a window, occupied by absolute or relative line number,
1058 * fold column and sign column (these don't move when scrolling horizontally). 1061 * fold column and sign column (these don't move when scrolling horizontally).
1997 win_T *wp, 2000 win_T *wp,
1998 int down) // when TRUE scroll down when not enough space 2001 int down) // when TRUE scroll down when not enough space
1999 { 2002 {
2000 int n; 2003 int n;
2001 2004
2002 if (wp->w_topfill > 0) 2005 if (wp->w_topfill <= 0)
2003 { 2006 return;
2004 n = plines_win_nofill(wp, wp->w_topline, TRUE); 2007
2005 if (wp->w_topfill + n > wp->w_height) 2008 n = plines_win_nofill(wp, wp->w_topline, TRUE);
2006 { 2009 if (wp->w_topfill + n > wp->w_height)
2007 if (down && wp->w_topline > 1) 2010 {
2008 { 2011 if (down && wp->w_topline > 1)
2009 --wp->w_topline; 2012 {
2013 --wp->w_topline;
2014 wp->w_topfill = 0;
2015 }
2016 else
2017 {
2018 wp->w_topfill = wp->w_height - n;
2019 if (wp->w_topfill < 0)
2010 wp->w_topfill = 0; 2020 wp->w_topfill = 0;
2011 }
2012 else
2013 {
2014 wp->w_topfill = wp->w_height - n;
2015 if (wp->w_topfill < 0)
2016 wp->w_topfill = 0;
2017 }
2018 } 2021 }
2019 } 2022 }
2020 } 2023 }
2021 2024
2022 /* 2025 /*