diff --git a/IPython/core/inputtransformer2.py b/IPython/core/inputtransformer2.py
index b73d70121..996a4f091 100644
--- a/IPython/core/inputtransformer2.py
+++ b/IPython/core/inputtransformer2.py
@@ -604,7 +604,7 @@ def check_complete(self, cell: str):
             else:
                 continue
 
-        if ends_with_newline:
+        if not ends_with_newline:
             # Append an newline for consistent tokenization
             # See https://bugs.python.org/issue33899
             cell += '\n'
@@ -649,10 +649,13 @@ def check_complete(self, cell: str):
 
         newline_types = {tokenize.NEWLINE, tokenize.COMMENT, tokenize.ENDMARKER}
 
-        # Remove newline_types for the list of tokens
-        while len(tokens_by_line) > 1 and len(tokens_by_line[-1]) == 1 \
-                and tokens_by_line[-1][-1].type in newline_types:
-            tokens_by_line.pop()
+        # Pop the last line which only contains DEDENTs and ENDMARKER
+        last_token_line = None
+        if {t.type for t in tokens_by_line[-1]} in [
+            {tokenize.DEDENT, tokenize.ENDMARKER},
+            {tokenize.ENDMARKER}
+        ] and len(tokens_by_line) > 1:
+            last_token_line = tokens_by_line.pop()
 
         while tokens_by_line[-1] and tokens_by_line[-1][-1].type in newline_types:
             tokens_by_line[-1].pop()
@@ -685,7 +688,7 @@ def check_complete(self, cell: str):
             if res is None:
                 return 'incomplete', find_last_indent(lines)
 
-        if tokens_by_line[-1][-1].type == tokenize.DEDENT:
+        if last_token_line and last_token_line[0].type == tokenize.DEDENT:
             if ends_with_newline:
                 return 'complete', None
             return 'incomplete', find_last_indent(lines)
diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py
index 152950ea1..2ee229137 100644
--- a/IPython/core/magics/execution.py
+++ b/IPython/core/magics/execution.py
@@ -507,7 +507,7 @@ def run(self, parameter_s='', runner=None,
         *two* back slashes (e.g. ``\\\\*``) to suppress expansions.
         To completely disable these expansions, you can use -G flag.
 
-        On Windows systems, the use of single quotes `'` when specifing 
+        On Windows systems, the use of single quotes `'` when specifying 
         a file is not supported. Use double quotes `"`.
 
         Options:
diff --git a/docs/source/whatsnew/version7.rst b/docs/source/whatsnew/version7.rst
index dc5a4d0e5..d84c21781 100644
--- a/docs/source/whatsnew/version7.rst
+++ b/docs/source/whatsnew/version7.rst
@@ -242,7 +242,7 @@ method ``cube()`` after it is uncommented and the file ``file1.py`` saved on
 disk.
 
 
-..code::
+.. code::
 
    # notebook
 

diff --git a/IPython/core/tests/test_inputtransformer2.py b/IPython/core/tests/test_inputtransformer2.py
index 9c92c394e..8d6efc1e2 100644
--- a/IPython/core/tests/test_inputtransformer2.py
+++ b/IPython/core/tests/test_inputtransformer2.py
@@ -225,7 +225,7 @@ def test_transform_help():
 
 def test_find_assign_op_dedent():
     """
-    be carefull that empty token like dedent are not counted as parens
+    be careful that empty token like dedent are not counted as parens
     """
     class Tk:
         def __init__(self, s):
@@ -238,6 +238,7 @@ def test_check_complete():
     cc = ipt2.TransformerManager().check_complete
     nt.assert_equal(cc("a = 1"), ('complete', None))
     nt.assert_equal(cc("for a in range(5):"), ('incomplete', 4))
+    nt.assert_equal(cc("for a in range(5):\n    if a > 0:"), ('incomplete', 8))
     nt.assert_equal(cc("raise = 2"), ('invalid', None))
     nt.assert_equal(cc("a = [1,\n2,"), ('incomplete', 0))
     nt.assert_equal(cc(")"), ('incomplete', 0))

Wrong autoindent for  class method. 
```
class F:
    def a(self):<enter>
```

Only 4 spaces are inserted. 

IPython/core/tests/test_inputtransformer2.py::test_check_complete
IPython/core/tests/test_inputtransformer2.py::test_continued_line IPython/core/tests/test_inputtransformer2.py::test_find_assign_magic IPython/core/tests/test_inputtransformer2.py::test_transform_assign_magic IPython/core/tests/test_inputtransformer2.py::test_find_assign_system IPython/core/tests/test_inputtransformer2.py::test_transform_assign_system IPython/core/tests/test_inputtransformer2.py::test_find_magic_escape IPython/core/tests/test_inputtransformer2.py::test_transform_magic_escape IPython/core/tests/test_inputtransformer2.py::test_find_autocalls IPython/core/tests/test_inputtransformer2.py::test_transform_autocall IPython/core/tests/test_inputtransformer2.py::test_find_help IPython/core/tests/test_inputtransformer2.py::test_transform_help IPython/core/tests/test_inputtransformer2.py::test_find_assign_op_dedent IPython/core/tests/test_inputtransformer2.py::test_check_complete_II IPython/core/tests/test_inputtransformer2.py::test_null_cleanup_transformer