Show More
@@ -288,9 +288,13 b' class IPythonCocoaController(NSObject, FrontEndBase):' | |||||
288 | def current_indent_string(self): |
|
288 | def current_indent_string(self): | |
289 | """returns string for indent or None if no indent""" |
|
289 | """returns string for indent or None if no indent""" | |
290 |
|
290 | |||
291 |
|
|
291 | return self._indent_for_block(self.currentBlock()) | |
292 | lines = self.current_block().split('\n') |
|
292 | ||
293 | currentIndent = len(lines[-1]) - len(lines[-1]) |
|
293 | ||
|
294 | def _indent_for_block(self, block): | |||
|
295 | lines = block.split('\n') | |||
|
296 | if(len(lines) > 1): | |||
|
297 | currentIndent = len(lines[-1]) - len(lines[-1].lstrip()) | |||
294 | if(currentIndent == 0): |
|
298 | if(currentIndent == 0): | |
295 | currentIndent = self.tabSpaces |
|
299 | currentIndent = self.tabSpaces | |
296 |
|
300 |
@@ -70,3 +70,22 b' class TestIPythonCocoaControler(DeferredTestCase):' | |||||
70 |
|
70 | |||
71 | self.controller.execute(code).addCallback(testCompletes) |
|
71 | self.controller.execute(code).addCallback(testCompletes) | |
72 |
|
72 | |||
|
73 | ||||
|
74 | def testCurrentIndent(self): | |||
|
75 | """test that current_indent_string returns current indent or None. | |||
|
76 | Uses _indent_for_block for direct unit testing. | |||
|
77 | """ | |||
|
78 | ||||
|
79 | self.controller.tabUsesSpaces = True | |||
|
80 | self.assert_(self.controller._indent_for_block("""a=3""") == None) | |||
|
81 | self.assert_(self.controller._indent_for_block("") == None) | |||
|
82 | block = """def test():\n a=3""" | |||
|
83 | self.assert_(self.controller._indent_for_block(block) == \ | |||
|
84 | ' ' * self.controller.tabSpaces) | |||
|
85 | ||||
|
86 | block = """if(True):\n%sif(False):\n%spass""" % \ | |||
|
87 | (' '*self.controller.tabSpaces, | |||
|
88 | 2*' '*self.controller.tabSpaces) | |||
|
89 | self.assert_(self.controller._indent_for_block(block) == \ | |||
|
90 | 2*(' '*self.controller.tabSpaces)) | |||
|
91 |
General Comments 0
You need to be logged in to leave comments.
Login now