From bbb0bc29712d8566506e286e5732d6245fd6a307 2017-05-04 16:38:22 From: meeseeksdev[bot] Date: 2017-05-04 16:38:22 Subject: [PATCH] Merge pull request #10489 from takluyver/i10425 Prefer execution when there's only a single line entered --- diff --git a/IPython/terminal/shortcuts.py b/IPython/terminal/shortcuts.py index 63c14a7..a96338d 100644 --- a/IPython/terminal/shortcuts.py +++ b/IPython/terminal/shortcuts.py @@ -113,8 +113,13 @@ def newline_or_execute_outer(shell): b.cancel_completion() return - before_text = d.text[:d.cursor_position] - status, indent = shell.input_splitter.check_complete(before_text + '\n') + # If there's only one line, treat it as if the cursor is at the end. + # See https://github.com/ipython/ipython/issues/10425 + if d.line_count == 1: + check_text = d.text + else: + check_text = d.text[:d.cursor_position] + status, indent = shell.input_splitter.check_complete(check_text + '\n') if not (d.on_last_line or d.cursor_position_row >= d.line_count - d.empty_line_count_at_the_end()