summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/editor.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-05-29 23:13:00 (GMT)
committerGitHub <noreply@github.com>2020-05-29 23:13:00 (GMT)
commit3dcccd1186febe0bca5936aed750d55c68b78bcd (patch)
treeb1554b722f98b96b880043edcac0c8961b23425e /Lib/idlelib/editor.py
parent00a240bf7f95bbd220f1cfbf9eb58484a5f9681a (diff)
downloadcpython-3dcccd1186febe0bca5936aed750d55c68b78bcd.zip
cpython-3dcccd1186febe0bca5936aed750d55c68b78bcd.tar.gz
cpython-3dcccd1186febe0bca5936aed750d55c68b78bcd.tar.bz2
bpo-39885: Make IDLE context menu cut and copy work again (GH-18951)
Leave selection when right click within. This exception to clearing selections when right-clicking was omitted from the previous commit, 4ca060d. I did not realize that this completely disabled the context menu entries, and I should have merged a minimal fix immediately. An automated test should follow. (cherry picked from commit 97e4e0f53d6690db6b942678489716a30925b8af) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib/idlelib/editor.py')
-rw-r--r--Lib/idlelib/editor.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py
index b0f88b5..a178eaf 100644
--- a/Lib/idlelib/editor.py
+++ b/Lib/idlelib/editor.py
@@ -499,15 +499,23 @@ class EditorWindow(object):
rmenu = None
def right_menu_event(self, event):
- self.text.tag_remove("sel", "1.0", "end")
- self.text.mark_set("insert", "@%d,%d" % (event.x, event.y))
+ text = self.text
+ newdex = text.index(f'@{event.x},{event.y}')
+ try:
+ in_selection = (text.compare('sel.first', '<=', newdex) and
+ text.compare(newdex, '<=', 'sel.last'))
+ except TclError:
+ in_selection = False
+ if not in_selection:
+ text.tag_remove("sel", "1.0", "end")
+ text.mark_set("insert", newdex)
if not self.rmenu:
self.make_rmenu()
rmenu = self.rmenu
self.event = event
iswin = sys.platform[:3] == 'win'
if iswin:
- self.text.config(cursor="arrow")
+ text.config(cursor="arrow")
for item in self.rmenu_specs:
try:
@@ -520,7 +528,6 @@ class EditorWindow(object):
state = getattr(self, verify_state)()
rmenu.entryconfigure(label, state=state)
-
rmenu.tk_popup(event.x_root, event.y_root)
if iswin:
self.text.config(cursor="ibeam")