diff options
author | Guido van Rossum <guido@python.org> | 1999-01-03 00:47:35 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-01-03 00:47:35 (GMT) |
commit | 33f2b7b2577ce0c9247c2eac0a29ce8212cdf829 (patch) | |
tree | 7ef6d6213ca3f29bd6528dd6bde9375c6899c00c | |
parent | 0c65e2504ef7e6d80babe911d991414f963cb08f (diff) | |
download | cpython-33f2b7b2577ce0c9247c2eac0a29ce8212cdf829.zip cpython-33f2b7b2577ce0c9247c2eac0a29ce8212cdf829.tar.gz cpython-33f2b7b2577ce0c9247c2eac0a29ce8212cdf829.tar.bz2 |
Added something like Tim Peters' backspace patch.
-rw-r--r-- | Tools/idle/AutoIndent.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/Tools/idle/AutoIndent.py b/Tools/idle/AutoIndent.py index 329f492..3f1dfe1 100644 --- a/Tools/idle/AutoIndent.py +++ b/Tools/idle/AutoIndent.py @@ -47,8 +47,12 @@ class AutoIndent: ]), ] - windows_keydefs = { + keydefs = { + '<<smart-backspace>>': ['<Key-BackSpace>'], '<<newline-and-indent>>': ['<Key-Return>', '<KP_Enter>'], + } + + windows_keydefs = { '<<indent-region>>': ['<Control-bracketright>'], '<<dedent-region>>': ['<Control-bracketleft>'], '<<comment-region>>': ['<Alt-Key-3>'], @@ -58,7 +62,6 @@ class AutoIndent: } unix_keydefs = { - '<<newline-and-indent>>': ['<Key-Return>', '<KP_Enter>'], '<<indent-region>>': ['<Alt-bracketright>', '<Meta-bracketright>', '<Control-bracketright>'], @@ -86,6 +89,29 @@ class AutoIndent: else: raise KeyError, "bad option name: %s" % `key` + def smart_backspace_event(self, event): + text = self.text + try: + first = text.index("sel.first") + last = text.index("sel.last") + except TclError: + first = last = None + if first and last: + text.delete(first, last) + text.mark_set("insert", first) + return "break" + # After Tim Peters + ndelete = 1 + chars = text.get("insert linestart", "insert") + i = 0 + n = len(chars) + while i < n and chars[i] in " \t": + i = i+1 + if i == n and chars[-4:] == " ": + ndelete = 4 + text.delete("insert - %d chars" % ndelete, "insert") + return "break" + def newline_and_indent_event(self, event): text = self.text try: |