From 3aff1e365ab5d0b38cee1f50a5281d76c7f3302d 2017-09-27 15:06:33 From: Thomas Kluyver Date: 2017-09-27 15:06:33 Subject: [PATCH] Identify position after a newline as the start of the next line Closes gh-10814 --- diff --git a/IPython/utils/tests/test_tokenutil.py b/IPython/utils/tests/test_tokenutil.py index 5e34b6e..d95d0fc 100644 --- a/IPython/utils/tests/test_tokenutil.py +++ b/IPython/utils/tests/test_tokenutil.py @@ -108,6 +108,12 @@ def test_line_at_cursor(): assert line == "", ("Expected '', got %r" % line) assert offset == 0, ("Expected '', got %r" % line) + # The position after a newline should be the start of the following line. + cell = "One\nTwo\n" + (line, offset) = line_at_cursor(cell, cursor_pos=4) + nt.assert_equal(line, "Two\n") + nt.assert_equal(offset, 4) + def test_muliline_statement(): cell = """a = (1, 3) diff --git a/IPython/utils/tokenutil.py b/IPython/utils/tokenutil.py index 9bc847a..9db6e71 100644 --- a/IPython/utils/tokenutil.py +++ b/IPython/utils/tokenutil.py @@ -44,7 +44,7 @@ def line_at_cursor(cell, cursor_pos=0): lines = cell.splitlines(True) for line in lines: next_offset = offset + len(line) - if next_offset >= cursor_pos: + if next_offset > cursor_pos: break offset = next_offset else: