diff --git a/src/winio.c b/src/winio.c
index 268c4bf8a24f836846f0dd13818eb52717d123d8..0ec0a3ffc28f967151637f73227889c1ce5169e0 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -3546,8 +3546,9 @@ void edit_scroll(updown direction, int nlines)
 
     /* Make nlines account for the lines before and after the scrolled
      * region, if they're onsccreen. */
-    nlines += (nlines <= editwinrows - 2) ? 2 :
-	(nlines == editwinrows - 1) ? 1 : 0;
+    nlines += 2;
+    if (nlines > editwinrows)
+	nlines = editwinrows;
 
     /* If we scrolled up, we're on the line before the scrolled
      * region. */