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()