Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ec186b

Browse files
committed
Patch 611069 (Christos Georgiou) IDLE TODO:left/right when selected text
M EditorWindow.py M NEWS.txt M TODO.txt
1 parent 9fd0799 commit 5ec186b

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

Lib/idlelib/EditorWindow.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
132132
text.bind("<<untabify-region>>",self.untabify_region_event)
133133
text.bind("<<toggle-tabs>>",self.toggle_tabs_event)
134134
text.bind("<<change-indentwidth>>",self.change_indentwidth_event)
135+
text.bind("<Left>", self.move_at_edge_if_selection(0))
136+
text.bind("<Right>", self.move_at_edge_if_selection(1))
135137

136138
if flist:
137139
flist.inversedict[self] = key
@@ -344,6 +346,26 @@ def remove_selection(self, event=None):
344346
self.text.tag_remove("sel", "1.0", "end")
345347
self.text.see("insert")
346348

349+
def move_at_edge_if_selection(self, edge_index):
350+
"""Cursor move begins at start or end of selection
351+
352+
When a left/right cursor key is pressed create and return to Tkinter a
353+
function which causes a cursor move from the associated edge of the
354+
selection.
355+
356+
"""
357+
self_text_index = self.text.index
358+
self_text_mark_set = self.text.mark_set
359+
edges_table = ("sel.first+1c", "sel.last-1c")
360+
def move_at_edge(event):
361+
if (event.state & 5) == 0: # no shift(==1) or control(==4) pressed
362+
try:
363+
self_text_index("sel.first")
364+
self_text_mark_set("insert", edges_table[edge_index])
365+
except TclError:
366+
pass
367+
return move_at_edge
368+
347369
def find_event(self, event):
348370
SearchDialog.find(self.text)
349371
return "break"

Lib/idlelib/NEWS.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ What's New in IDLEfork 0.9 Alpha 2?
77

88
*Release date: XX-XXX-2003*
99

10+
- Left cursor move in presence of selected text now moves from left end
11+
of the selection.
12+
13+
- Add Meta keybindings to "IDLE Classic Windows" to handle reversed
14+
Alt/Meta on some Linux distros.
15+
1016
- Change default: IDLE now starts with Python Shell.
1117

1218
- Removed the File Path from the Additional Help Sources scrolled list.

Lib/idlelib/TODO.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ TO DO:
4646

4747
Details:
4848

49-
- when there's a selection, left/right arrow should go to either
50-
end of the selection
5149
- ^O (on Unix -- open-line) should honor autoindent
5250
- after paste, show end of pasted text
5351
- on Windows, should turn short filename to long filename (not only in argv!)

0 commit comments

Comments
 (0)