diff options
author | 2011-07-07 22:42:39 -0400 | |
---|---|---|
committer | 2011-07-07 22:42:39 -0400 | |
commit | 6670c0513866b42a44bf5fdf494d8509908ff45b (patch) | |
tree | c3e083e6d79d3aa8c6c2729af50e40086a197421 | |
parent | bd4227bd775cfd3a0aa6ba565c079187e8ccbda0 (diff) | |
download | textadept-6670c0513866b42a44bf5fdf494d8509908ff45b.tar.gz textadept-6670c0513866b42a44bf5fdf494d8509908ff45b.zip |
Detect Alt/Option modifier on Mac OSX.
-rw-r--r-- | core/events.lua | 2 | ||||
-rw-r--r-- | core/keys.lua | 21 | ||||
-rw-r--r-- | src/textadept.c | 3 |
3 files changed, 20 insertions, 6 deletions
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.<br /> -- * `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.<br /> -- * `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() diff --git a/src/textadept.c b/src/textadept.c index f8ab3758..d9874dd2 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -40,7 +40,8 @@ l_emit_event(name, LUA_TNUMBER, event->keyval, LUA_TBOOLEAN, \ event->state & GDK_SHIFT_MASK, LUA_TBOOLEAN, \ event->state & GDK_CONTROL_MASK, LUA_TBOOLEAN, \ - event->state & GDK_MOD1_MASK, -1) + event->state & GDK_MOD1_MASK, LUA_TBOOLEAN, \ + event->state & GDK_MOD5_MASK, -1) #define l_mt(l, k, i, ni) { \ if (luaL_newmetatable(l, k)) { \ l_cfunc(l, i, "__index"); \ |