mirror of
https://github.com/andrey271192/ssh-manage.git
synced 2026-09-21 12:02:01 +00:00
fix: macOS Cmd+V paste — bind <Command-v> directly (Tk 8.6 bug)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -492,10 +492,10 @@ def agent_search(query):
|
|||||||
|
|
||||||
|
|
||||||
def setup_entry_clipboard(entry):
|
def setup_entry_clipboard(entry):
|
||||||
"""Add right-click context menu to tk.Entry. Keyboard shortcuts (Cmd+V/C/X)
|
"""Fix clipboard on macOS (Tk 8.6 maps <<Paste>> to Mod1 not Command)
|
||||||
are handled by tkinter's built-in Entry bindings — do NOT override them."""
|
and add right-click context menu."""
|
||||||
|
|
||||||
def _paste():
|
def _paste(e=None):
|
||||||
try:
|
try:
|
||||||
text = entry.clipboard_get()
|
text = entry.clipboard_get()
|
||||||
if entry.selection_present():
|
if entry.selection_present():
|
||||||
@@ -503,20 +503,24 @@ def setup_entry_clipboard(entry):
|
|||||||
entry.insert(tk.INSERT, text)
|
entry.insert(tk.INSERT, text)
|
||||||
except tk.TclError:
|
except tk.TclError:
|
||||||
pass
|
pass
|
||||||
|
return "break"
|
||||||
|
|
||||||
def _copy():
|
def _copy(e=None):
|
||||||
if entry.selection_present():
|
if entry.selection_present():
|
||||||
entry.clipboard_clear()
|
entry.clipboard_clear()
|
||||||
entry.clipboard_append(entry.selection_get())
|
entry.clipboard_append(entry.selection_get())
|
||||||
|
return "break"
|
||||||
|
|
||||||
def _cut():
|
def _cut(e=None):
|
||||||
|
_copy()
|
||||||
if entry.selection_present():
|
if entry.selection_present():
|
||||||
_copy()
|
|
||||||
entry.delete(tk.SEL_FIRST, tk.SEL_LAST)
|
entry.delete(tk.SEL_FIRST, tk.SEL_LAST)
|
||||||
|
return "break"
|
||||||
|
|
||||||
def _select_all():
|
def _select_all(e=None):
|
||||||
entry.select_range(0, tk.END)
|
entry.select_range(0, tk.END)
|
||||||
entry.icursor(tk.END)
|
entry.icursor(tk.END)
|
||||||
|
return "break"
|
||||||
|
|
||||||
def _context_menu(event):
|
def _context_menu(event):
|
||||||
menu = tk.Menu(entry, tearoff=0, bg="#313244", fg="#cdd6f4",
|
menu = tk.Menu(entry, tearoff=0, bg="#313244", fg="#cdd6f4",
|
||||||
@@ -528,12 +532,19 @@ def setup_entry_clipboard(entry):
|
|||||||
menu.add_command(label="Выделить всё", command=_select_all)
|
menu.add_command(label="Выделить всё", command=_select_all)
|
||||||
menu.tk_popup(event.x_root, event.y_root)
|
menu.tk_popup(event.x_root, event.y_root)
|
||||||
|
|
||||||
# Right-click context menu only — keyboard handled by tkinter defaults
|
|
||||||
entry.bind("<Button-3>", _context_menu)
|
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
|
# macOS Tk 8.6 bug: <<Paste>> bound to Mod1 (Option) not Command
|
||||||
|
# Manually bind Command+key for clipboard operations
|
||||||
|
entry.bind("<Command-v>", _paste)
|
||||||
|
entry.bind("<Command-c>", _copy)
|
||||||
|
entry.bind("<Command-x>", _cut)
|
||||||
|
entry.bind("<Command-a>", _select_all)
|
||||||
|
# Right-click
|
||||||
entry.bind("<Button-2>", _context_menu)
|
entry.bind("<Button-2>", _context_menu)
|
||||||
entry.bind("<Control-Button-1>", _context_menu)
|
entry.bind("<Control-Button-1>", _context_menu)
|
||||||
|
|
||||||
|
entry.bind("<Button-3>", _context_menu)
|
||||||
|
|
||||||
|
|
||||||
def app_dir():
|
def app_dir():
|
||||||
if getattr(sys, "frozen", False):
|
if getattr(sys, "frozen", False):
|
||||||
|
|||||||
Reference in New Issue
Block a user