diff --git a/src/ansi.c b/src/ansi.c
index e76eef4..bbdc119 100644
--- a/ansi.c
+++ b/ansi.c
@@ -1444,8 +1444,8 @@ int c, intermediate;
 		  else
 		    {
 		      if (curr->w_alt.on) {
-		        LeaveAltScreen(curr);
-		        RestoreCursor(&curr->w_alt.cursor);
+		        RestoreCursor(&curr->w_alt.cursor);
+		        LeaveAltScreen(curr);
 		      }
 		    }
 		  if (a1 == 47 && !i)

