@@ -4218,18 +4218,19 @@ win_find_tabpage(win_T *win)
42184218#endif
42194219
42204220/*
4221- * Move to window above or below "count" times.
4221+ * Get the above or below neighbor window of the specified window.
4222+ * up - TRUE for the above neighbor
4223+ * count - nth neighbor window
4224+ * Returns the specified window if the neighbor is not found.
42224225 */
4223- static void
4224- win_goto_ver (
4225- int up , /* TRUE to go to win above */
4226- long count )
4226+ win_T *
4227+ win_vert_neighbor (tabpage_T * tp , win_T * wp , int up , long count )
42274228{
42284229 frame_T * fr ;
42294230 frame_T * nfr ;
42304231 frame_T * foundfr ;
42314232
4232- foundfr = curwin -> w_frame ;
4233+ foundfr = wp -> w_frame ;
42334234 while (count -- )
42344235 {
42354236 /*
@@ -4239,7 +4240,7 @@ win_goto_ver(
42394240 fr = foundfr ;
42404241 for (;;)
42414242 {
4242- if (fr == topframe )
4243+ if (fr == tp -> tp_topframe )
42434244 goto end ;
42444245 if (up )
42454246 nfr = fr -> fr_prev ;
@@ -4266,7 +4267,7 @@ win_goto_ver(
42664267 /* Find the frame at the cursor row. */
42674268 while (fr -> fr_next != NULL
42684269 && frame2win (fr )-> w_wincol + fr -> fr_width
4269- <= curwin -> w_wincol + curwin -> w_wcol )
4270+ <= wp -> w_wincol + wp -> w_wcol )
42704271 fr = fr -> fr_next ;
42714272 }
42724273 if (nfr -> fr_layout == FR_COL && up )
@@ -4276,23 +4277,38 @@ win_goto_ver(
42764277 }
42774278 }
42784279end :
4279- if (foundfr != NULL )
4280- win_goto (foundfr -> fr_win );
4280+ return foundfr != NULL ? foundfr -> fr_win : NULL ;
42814281}
42824282
42834283/*
4284- * Move to left or right window .
4284+ * Move to window above or below "count" times .
42854285 */
42864286 static void
4287- win_goto_hor (
4288- int left , /* TRUE to go to left win */
4287+ win_goto_ver (
4288+ int up , // TRUE to go to win above
42894289 long count )
4290+ {
4291+ win_T * win ;
4292+
4293+ win = win_vert_neighbor (curtab , curwin , up , count );
4294+ if (win != NULL )
4295+ win_goto (win );
4296+ }
4297+
4298+ /*
4299+ * Get the left or right neighbor window of the specified window.
4300+ * left - TRUE for the left neighbor
4301+ * count - nth neighbor window
4302+ * Returns the specified window if the neighbor is not found.
4303+ */
4304+ win_T *
4305+ win_horz_neighbor (tabpage_T * tp , win_T * wp , int left , long count )
42904306{
42914307 frame_T * fr ;
42924308 frame_T * nfr ;
42934309 frame_T * foundfr ;
42944310
4295- foundfr = curwin -> w_frame ;
4311+ foundfr = wp -> w_frame ;
42964312 while (count -- )
42974313 {
42984314 /*
@@ -4302,7 +4318,7 @@ win_goto_hor(
43024318 fr = foundfr ;
43034319 for (;;)
43044320 {
4305- if (fr == topframe )
4321+ if (fr == tp -> tp_topframe )
43064322 goto end ;
43074323 if (left )
43084324 nfr = fr -> fr_prev ;
@@ -4329,7 +4345,7 @@ win_goto_hor(
43294345 /* Find the frame at the cursor row. */
43304346 while (fr -> fr_next != NULL
43314347 && frame2win (fr )-> w_winrow + fr -> fr_height
4332- <= curwin -> w_winrow + curwin -> w_wrow )
4348+ <= wp -> w_winrow + wp -> w_wrow )
43334349 fr = fr -> fr_next ;
43344350 }
43354351 if (nfr -> fr_layout == FR_ROW && left )
@@ -4339,8 +4355,22 @@ win_goto_hor(
43394355 }
43404356 }
43414357end :
4342- if (foundfr != NULL )
4343- win_goto (foundfr -> fr_win );
4358+ return foundfr != NULL ? foundfr -> fr_win : NULL ;
4359+ }
4360+
4361+ /*
4362+ * Move to left or right window.
4363+ */
4364+ static void
4365+ win_goto_hor (
4366+ int left , // TRUE to go to left win
4367+ long count )
4368+ {
4369+ win_T * win ;
4370+
4371+ win = win_horz_neighbor (curtab , curwin , left , count );
4372+ if (win != NULL )
4373+ win_goto (win );
43444374}
43454375
43464376/*
0 commit comments