Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/idlelib/config-keys.def
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ goto-line=<Alt-Key-g> <Meta-Key-g> <Alt-Key-G> <Meta-Key-G>
smart-backspace=<Key-BackSpace>
newline-and-indent=<Key-Return> <Key-KP_Enter>
smart-indent=<Key-Tab>
smart-dedent=<Shift-Key-Tab>
indent-region=<Control-Key-bracketright>
dedent-region=<Control-Key-bracketleft>
comment-region=<Alt-Key-3> <Meta-Key-3>
Expand Down Expand Up @@ -107,6 +108,7 @@ goto-line=<Alt-Key-g> <Meta-Key-g>
smart-backspace=<Key-BackSpace>
newline-and-indent=<Key-Return> <Key-KP_Enter>
smart-indent=<Key-Tab>
smart-dedent=<Shift-Key-Tab>
indent-region=<Control-Key-bracketright>
dedent-region=<Control-Key-bracketleft>
comment-region=<Alt-Key-3>
Expand Down Expand Up @@ -167,6 +169,7 @@ goto-line = <Control-Key-g>
smart-backspace = <Key-BackSpace>
newline-and-indent = <Key-Return> <Key-KP_Enter>
smart-indent = <Key-Tab>
smart-dedent = <Shift-Key-Tab>
indent-region = <Control-Key-bracketright>
dedent-region = <Control-Key-bracketleft>
comment-region = <Control-Key-d>
Expand Down Expand Up @@ -227,6 +230,7 @@ goto-line=<Command-Key-j>
smart-backspace=<Key-BackSpace>
newline-and-indent=<Key-Return> <Key-KP_Enter>
smart-indent=<Key-Tab>
smart-dedent=<Shift-Key-Tab>
indent-region=<Command-Key-bracketright>
dedent-region=<Command-Key-bracketleft>
comment-region=<Control-Key-3>
Expand Down Expand Up @@ -275,6 +279,7 @@ smart-backspace = <Key-BackSpace>
change-indentwidth = <Control-Key-u>
do-nothing = <Control-Key-F12>
smart-indent = <Key-Tab>
smart-dedent = <Shift-Key-Tab>
center-insert = <Control-Key-l>
history-next = <Control-Key-n>
del-word-right = <Option-Key-Delete>
Expand Down
1 change: 1 addition & 0 deletions Lib/idlelib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ def GetCoreKeys(self, keySetName=None):
'<<smart-backspace>>': ['<Key-BackSpace>'],
'<<newline-and-indent>>': ['<Key-Return>', '<Key-KP_Enter>'],
'<<smart-indent>>': ['<Key-Tab>'],
'<<smart-dedent>>': ['<Shift-Key-Tab>', '<Shift-ISO_Left_Tab>'],
'<<indent-region>>': ['<Control-Key-bracketright>'],
'<<dedent-region>>': ['<Control-Key-bracketleft>'],
'<<comment-region>>': ['<Alt-Key-3>'],
Expand Down
18 changes: 18 additions & 0 deletions Lib/idlelib/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
text.bind("<<smart-backspace>>",self.smart_backspace_event)
text.bind("<<newline-and-indent>>",self.newline_and_indent_event)
text.bind("<<smart-indent>>",self.smart_indent_event)
text.bind("<<smart-dedent>>", self.smart_dedent_event)
self.fregion = fregion = self.FormatRegion(self)
# self.fregion used in smart_indent_event to access indent_region.
text.bind("<<indent-region>>", fregion.indent_region_event)
Expand Down Expand Up @@ -1426,6 +1427,23 @@ def smart_indent_event(self, event):
finally:
text.undo_block_stop()

def smart_dedent_event(self, event):
text = self.text
first, last = self.get_selection_indices()
text.undo_block_start()
try:
if first and last:
if index2line(first) != index2line(last):
return self.fregion.dedent_region_event(event)
prefix = text.get("insert linestart", "insert")
raw, effective = get_line_indent(prefix, self.tabwidth)
if raw == len(prefix) and effective > 0:
self.reindent_to(max(0, effective - self.indentwidth))
text.see("insert")
return "break"
finally:
text.undo_block_stop()

def newline_and_indent_event(self, event):
"""Insert a newline and indentation after Enter keypress event.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add smart-dedent bound to Shift-Tab in IDLE to dedent selected lines or the current line.
Loading