Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
disable shell sidebar context-menu copying when there is no selection
  • Loading branch information
taleinat committed May 1, 2021
commit d790175e1df5d1e2e26a324fd59389e9ecd96e86
13 changes: 9 additions & 4 deletions Lib/idlelib/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

def get_lineno(text, index):
"""Return the line number of an index in a Tk text widget."""
return int(float(text.index(index)))
text_index = text.index(index)
return int(float(text_index)) if text_index else None


def get_end_linenumber(text):
Expand Down Expand Up @@ -440,11 +441,15 @@ def bind_events(self):

def context_menu_event(self, event):
rmenu = tk.Menu(self.main_widget, tearoff=0)
rmenu.add_command(label='Copy', command=self.rmenu_copy_handler)
has_selection = bool(self.text.tag_nextrange('sel', '1.0'))
rmenu.add_command(label='Copy', command=self.rmenu_copy_handler,
state='normal' if has_selection else 'disabled')
rmenu.add_command(label='Copy with prompts',
command=self.rmenu_copy_with_prompts_handler)
command=self.rmenu_copy_with_prompts_handler,
state='normal' if has_selection else 'disabled')
rmenu.add_command(label='Copy only code',
command=self.rmenu_copy_only_code_handler)
command=self.rmenu_copy_only_code_handler,
state='normal' if has_selection else 'disabled')
rmenu.tk_popup(event.x_root, event.y_root)
return "break"

Expand Down