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

Update macOS key bindings #27

Open
wants to merge 1 commit into
base: OT
Choose a base branch
from
Open
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
34 changes: 31 additions & 3 deletions src/interface/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def __init__(self, client, title, language, logging=False):
# Key bindings

CtrlKey = "Command" if SYSTEM == MAC_OS else "Control"
AltKey = "Option" if SYSTEM == MAC_OS else "Alt"

# Disable by default

Expand All @@ -212,17 +213,39 @@ def __init__(self, client, title, language, logging=False):

self.text.bind("escape", disable)

drop_event = lambda fun: lambda event: fun()

# Basic mappings

if SYSTEM == MAC_OS:
self.text.bind("<Control-a>", drop_event(self.key_home))
self.text.bind("<Control-e>", drop_event(self.key_end))

# Evaluating code

self.text.bind("<Key>", self.key_press)

self.text.bind("<{}-Return>".format(CtrlKey), self.evaluate)
self.text.bind("<Alt-Return>", self.single_line_evaluate)
self.text.bind("<{}-Return>".format(AltKey), self.single_line_evaluate)
self.text.bind("<Shift-Return>", self.single_line_evaluate)

if SYSTEM == MAC_OS:
self.text.bind("<{}-Right>".format(AltKey), self.key_ctrl_right)
self.text.bind("<{}-Left>".format(AltKey), self.key_ctrl_left)
else:
self.text.bind("<{}-Right>".format(CtrlKey), self.key_ctrl_right)
self.text.bind("<{}-Left>".format(CtrlKey), self.key_ctrl_left)

self.text.bind("<{}-Right>".format(CtrlKey), self.key_ctrl_right)
self.text.bind("<{}-Left>".format(CtrlKey), self.key_ctrl_left)
if SYSTEM == MAC_OS:
self.text.bind("<{}-Right>".format(CtrlKey), drop_event(self.key_end))
self.text.bind("<{}-Left>".format(CtrlKey), drop_event(self.key_home))

self.text.bind("<{}-Up>".format(CtrlKey), self.key_ctrl_home)
self.text.bind("<{}-Down>".format(CtrlKey), self.key_ctrl_end)

self.text.bind("<{}-Home>".format(CtrlKey), self.key_ctrl_home)
self.text.bind("<{}-End>".format(CtrlKey), self.key_ctrl_end)

self.text.bind("<{}-period>".format(CtrlKey), self.stop_sound)

self.text.bind("<{}-BackSpace>".format(CtrlKey), self.key_ctrl_backspace)
Expand All @@ -242,6 +265,11 @@ def __init__(self, client, title, language, logging=False):
self.text.bind("<Shift-Down>", self.select_down)
self.text.bind("<Shift-End>", self.select_end)
self.text.bind("<Shift-Home>", self.select_home)

if SYSTEM == MAC_OS:
self.text.bind("<{}-Shift-Right>".format(CtrlKey), self.select_end)
self.text.bind("<{}-Shift-Left>".format(CtrlKey), self.select_home)

self.text.bind("<{}-a>".format(CtrlKey), self.select_all)

# Copy and paste key bindings
Expand Down