summaryrefslogtreecommitdiff
authorOwen W. Taylor <otaylor@fishsoup.net>2009-03-21 16:59:58 (GMT)
committer Owen W. Taylor <otaylor@fishsoup.net>2009-03-21 16:59:58 (GMT)
commita210f165ed2ad18812f85d07f55086f4ee45895f (patch)
tree13f7aebcb57aca14671e168fd9a929ccd45661d9
parentec26b2b2c7b4ae40800ff65e12f318dc3de2ef37 (diff)
Ignore whitespace lines for outdents
When determining the proper outdent when the user hits delete, ignore lines that only have whitespace on them. http://www.reinteract.org/trac/ticket/72
-rwxr-xr-xlib/reinteract/shell_view.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/reinteract/shell_view.py b/lib/reinteract/shell_view.py
index 6285227..382bb09 100755
--- a/lib/reinteract/shell_view.py
+++ b/lib/reinteract/shell_view.py
@@ -18,6 +18,8 @@ import sanitize_textview_ipc
LEFT_MARGIN_WIDTH = 10
+ALL_WHITESPACE_RE = re.compile("^\s*$")
+
class ShellView(gtk.TextView):
__gsignals__ = {
'backspace' : 'override',
@@ -223,7 +225,7 @@ class ShellView(gtk.TextView):
return start.get_slice(end)
# This is likely overengineered, since we're going to try as hard as possible not to
- # have tabs in our worksheets
+ # have tabs in our worksheets. We don't do the funky handling of \f.
def __count_indent(self, text):
indent = 0
for c in text:
@@ -245,6 +247,9 @@ class ShellView(gtk.TextView):
while line > 0:
line -= 1
line_text = buf.worksheet.get_line(line)
+ # Empty lines don't establish indentation
+ if ALL_WHITESPACE_RE.match(line_text):
+ continue
indent = self.__count_indent(line_text)
if indent < current_indent: