From 6670c0513866b42a44bf5fdf494d8509908ff45b Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Thu, 7 Jul 2011 22:42:39 -0400 Subject: Detect Alt/Option modifier on Mac OSX. --- core/events.lua | 2 ++ core/keys.lua | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/events.lua b/core/events.lua index 6b8ac99b..cea75a71 100644 --- a/core/events.lua +++ b/core/events.lua @@ -66,6 +66,7 @@ module('events', package.seeall) -- * `shift`: The Shift key is held down. -- * `ctrl`: The Control key is held down. -- * `alt`: The Alt/Apple key is held down. +-- * `option`: The Alt/Option key on Mac OSX is held down. -- * `DOUBLE_CLICK`: Called when the mouse button is double-clicked.
-- * `position`: The text position of the double click. -- * `line`: The line of the double click. @@ -114,6 +115,7 @@ module('events', package.seeall) -- * `shift`: The Shift key is held down. -- * `ctrl`: The Control key is held down. -- * `alt`: The Alt/Apple key is held down. +-- * `option`: The Alt/Option key on Mac OSX is held down. -- * `MARGIN_CLICK`: Called when the mouse is clicked inside a margin.
-- * `margin`: The margin number that was clicked. -- * `position`: The position of the start of the line in the buffer that diff --git a/core/keys.lua b/core/keys.lua index 1fe62b17..7b121e3a 100644 --- a/core/keys.lua +++ b/core/keys.lua @@ -21,14 +21,15 @@ module('keys', package.seeall) -- and `lua`. -- -- A key command string is built from a combination of the `CTRL`, `SHIFT`, --- `ALT`, and `ADD` constants as well as the pressed key itself. The value of --- `ADD` is inserted between each of `CTRL`, `SHIFT`, `ALT`, and the key. --- For example: +-- `ALT`, `OPTION`, and `ADD` constants as well as the pressed key itself. The +-- value of `ADD` is inserted between each of `CTRL`, `SHIFT`, `ALT`, `OPTION`, +-- and the key. For example: -- -- -- keys.lua: -- CTRL = 'Ctrl' -- SHIFT = 'Shift' -- ALT = 'Alt' +-- OPTION = 'Option' -- ADD = '+' -- -- pressing control, shift, alt and 'a' yields: 'Ctrl+Shift+Alt+A' -- @@ -55,6 +56,7 @@ module('keys', package.seeall) -- * `SHIFT` [string]: The string representing the Shift key. -- * `ALT` [string]: The string representing the Alt key (the Apple key on Mac -- OSX). +-- * `OPTION` [string]: The string representing the Alt/Option key on Mac OSX. -- * `ADD` [string]: The string representing used to join together a sequence of -- Control, Shift, or Alt modifier keys. -- @@ -89,6 +91,7 @@ local ADD = '' local CTRL = 'c'..ADD local SHIFT = 's'..ADD local ALT = 'a'..ADD +local OPTION = 'o'..ADD -- end settings -- Optimize for speed. @@ -185,9 +188,16 @@ end -- Handles Textadept keypresses. -- It is called every time a key is pressed, and based on lexer, executes a -- command. The command is looked up in the global 'keys' key command table. +-- @param code The keycode. +-- @param shift Flag indicating whether or not the shift modifier is pressed. +-- @param control Flag indicating whether or not the control modifier is +-- pressed. +-- @param alt Flag indicating whether or not the alt/apple modifier is pressed. +-- @param option Flag indicating whether the alt/option key is pressed. (Only +-- on Mac OSX.) -- @return whatever the executed command returns, true by default. A true -- return value will tell Textadept not to handle the key afterwords. -local function keypress(code, shift, control, alt) +local function keypress(code, shift, control, alt, option) local buffer = buffer local key --print(code, string.char(code)) @@ -201,7 +211,8 @@ local function keypress(code, shift, control, alt) control = control and CTRL or '' shift = shift and SHIFT or '' alt = alt and ALT or '' - local key_seq = control..shift..alt..key + option = option and OPTION or '' + local key_seq = control..shift..alt..option..key if #keychain > 0 and key_seq == keys.clear_sequence then clear_key_sequence() -- cgit v1.2.3