patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move

Problem:    A BufReadPre autocommand may cause the cursor to move.
Solution:   Restore the cursor position after executing the autocommand,
            unless the autocommand moved it. (Christian Brabandt,
            closes #4302, closes #4294)
diff --git a/src/autocmd.c b/src/autocmd.c
index 2ea23cc..e6cdb36 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -2123,9 +2123,16 @@
 	for (ap = patcmd.curpat; ap->next != NULL; ap = ap->next)
 	    ap->last = FALSE;
 	ap->last = TRUE;
-	check_lnums(TRUE);	// make sure cursor and topline are valid
+
+	// make sure cursor and topline are valid
+	check_lnums(TRUE);
+
 	do_cmdline(NULL, getnextac, (void *)&patcmd,
 				     DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
+
+	// restore cursor and topline, unless they were changed
+	reset_lnums();
+
 #ifdef FEAT_EVAL
 	if (eap != NULL)
 	{