Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-38066: IDLE: Dedenting with shift+tab #2210

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@ -98,6 +99,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-ISO_Left_Tab>
indent-region=<Control-Key-bracketright>
dedent-region=<Control-Key-bracketleft>
comment-region=<Alt-Key-3>
Expand Down Expand Up @@ -149,6 +151,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-ISO_Left_Tab>
indent-region = <Control-Key-bracketright>
dedent-region = <Control-Key-bracketleft>
comment-region = <Control-Key-d>
Expand Down Expand Up @@ -200,6 +203,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 @@ -239,6 +243,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 @@ -649,6 +649,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-ISO_Left_Tab>', '<Shift-Key-Tab>'],
'<<indent-region>>': ['<Control-Key-bracketright>'],
'<<dedent-region>>': ['<Control-Key-bracketleft>'],
'<<comment-region>>': ['<Alt-Key-3>'],
Expand Down
22 changes: 22 additions & 0 deletions Lib/idlelib/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,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)
text.bind("<<indent-region>>",self.indent_region_event)
text.bind("<<dedent-region>>",self.dedent_region_event)
text.bind("<<comment-region>>",self.comment_region_event)
Expand Down Expand Up @@ -1216,6 +1217,27 @@ def smart_indent_event(self, event):
finally:
text.undo_block_stop()

def smart_dedent_event(self, event):
# if selection:
# do dedent-region
# elif only whitespace to the left:
# dedent one level
first, last = self.get_selection_indices()
self.text.undo_block_start()
try:
if first and last:
if index2line(first) != index2line(last):
return self.dedent_region_event(event)
prefix = self.text.get('insert linestart', 'insert')
raw, effective = classifyws(prefix, self.tabwidth)
if raw == len(prefix):
# Only whitespace to the left
self.reindent_to(effective - self.indentwidth)
self.text.see('insert')
return 'break'
finally:
self.text.undo_block_stop()

def newline_and_indent_event(self, event):
text = self.text
first, last = self.get_selection_indices()
Expand Down