Show More
@@ -105,8 +105,20 b' def test_attrs():' | |||||
105 | def test_line_at_cursor(): |
|
105 | def test_line_at_cursor(): | |
106 | cell = "" |
|
106 | cell = "" | |
107 | (line, offset) = line_at_cursor(cell, cursor_pos=11) |
|
107 | (line, offset) = line_at_cursor(cell, cursor_pos=11) | |
108 | assert line == "", ("Expected '', got %r" % line) |
|
108 | nt.assert_equal(line, "") | |
109 | assert offset == 0, ("Expected '', got %r" % line) |
|
109 | nt.assert_equal(offset, 0) | |
|
110 | ||||
|
111 | # The position after a newline should be the start of the following line. | |||
|
112 | cell = "One\nTwo\n" | |||
|
113 | (line, offset) = line_at_cursor(cell, cursor_pos=4) | |||
|
114 | nt.assert_equal(line, "Two\n") | |||
|
115 | nt.assert_equal(offset, 4) | |||
|
116 | ||||
|
117 | # The end of a cell should be on the last line | |||
|
118 | cell = "pri\npri" | |||
|
119 | (line, offset) = line_at_cursor(cell, cursor_pos=7) | |||
|
120 | nt.assert_equal(line, "pri") | |||
|
121 | nt.assert_equal(offset, 4) | |||
110 |
|
122 | |||
111 | def test_muliline_statement(): |
|
123 | def test_muliline_statement(): | |
112 | cell = """a = (1, |
|
124 | cell = """a = (1, |
@@ -44,7 +44,12 b' def line_at_cursor(cell, cursor_pos=0):' | |||||
44 | lines = cell.splitlines(True) |
|
44 | lines = cell.splitlines(True) | |
45 | for line in lines: |
|
45 | for line in lines: | |
46 | next_offset = offset + len(line) |
|
46 | next_offset = offset + len(line) | |
47 | if next_offset >= cursor_pos: |
|
47 | if not line.endswith('\n'): | |
|
48 | # If the last line doesn't have a trailing newline, treat it as if | |||
|
49 | # it does so that the cursor at the end of the line still counts | |||
|
50 | # as being on that line. | |||
|
51 | next_offset += 1 | |||
|
52 | if next_offset > cursor_pos: | |||
48 | break |
|
53 | break | |
49 | offset = next_offset |
|
54 | offset = next_offset | |
50 | else: |
|
55 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now