Added something like Tim Peters' backspace patch.

This commit is contained in:
Guido van Rossum 1999-01-03 00:47:35 +00:00
parent 0c65e2504e
commit 33f2b7b257
1 changed files with 28 additions and 2 deletions

View File

@ -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: