aboutsummaryrefslogtreecommitdiff
path: root/core/keys.lua
diff options
context:
space:
mode:
authormitchell <70453897+orbitalquark@users.noreply.github.com>2020-10-20 15:29:03 -0400
committermitchell <70453897+orbitalquark@users.noreply.github.com>2020-10-20 15:29:03 -0400
commit03c4016d07477781aa3adcc9edf340c0bec9c6c8 (patch)
treed3be089e9020807326a4e56562876ecb7bcf7892 /core/keys.lua
parentb682fbd4a6e53185e2556686079532ad0e42be94 (diff)
downloadtextadept-03c4016d07477781aa3adcc9edf340c0bec9c6c8.tar.gz
textadept-03c4016d07477781aa3adcc9edf340c0bec9c6c8.zip
Code cleanup.
Of note: * io.save_all_files() does not visit each buffer to save anymore. An unintended side-effect was checking for outside modification (but only if the file itself was modified), so outside changes will always be saved over now. * The menu clicked handler uses assert_type(), so the 'Unknown command' localization is no longer needed. * When printing to a new buffer type would split the view, use an existing split view when possible. * Prefer 'goto continue' construct in loops over nested 'if's. * Fixed clearing of ui.find.replace_entry_text on reset in the GUI version. * Fixed lack of statusbar updating when setting options like buffer EOL mode, indentation, and encoding. * Renamed internal new_snippet() to new() and put it in the snippet metatable.
Diffstat (limited to 'core/keys.lua')
-rw-r--r--core/keys.lua27
1 files changed, 9 insertions, 18 deletions
diff --git a/core/keys.lua b/core/keys.lua
index ac9523ab..2d4d8781 100644
--- a/core/keys.lua
+++ b/core/keys.lua
@@ -112,8 +112,8 @@ local M = {}
-- The default value is `nil`.
module('keys')]]
-local CTRL, ALT, SHIFT = 'ctrl+', not CURSES and 'alt+' or 'meta+', 'shift+'
-local CMD = 'cmd+'
+local CTRL, ALT, CMD, SHIFT = 'ctrl+', 'alt+', 'cmd+', 'shift+'
+if CURSES then ALT = 'meta+' end
M.CLEAR = 'esc'
---
@@ -151,7 +151,7 @@ local INVALID, PROPAGATE, CHAIN, HALT = -1, 0, 1, 2
-- Error handler for key commands that simply emits the error. This is needed
-- so `key_command()` can return `HALT` instead of never returning due to the
-- error.
-local function key_error(e) events.emit(events.ERROR, e) end
+local function key_error(errmsg) events.emit(events.ERROR, errmsg) end
-- Runs a key command associated with the current keychain.
-- @param prefix Optional prefix name for mode/lexer-specific commands.
@@ -171,19 +171,11 @@ local function key_command(prefix)
return select(2, xpcall(key, key_error)) == false and PROPAGATE or HALT
end
--- Handles Textadept keypresses.
--- It is called every time a key is pressed, and based on a mode or lexer,
--- executes a command. The command is looked up in the `_G.keys` table.
--- @param code The keycode.
--- @param shift Whether or not the Shift modifier is pressed.
--- @param control Whether or not the Control modifier is pressed.
--- @param alt Whether or not the Alt/option modifier is pressed.
--- @param cmd Whether or not the Command modifier on macOS is pressed.
--- @param caps_lock Whether or not Caps Lock is enabled.
--- @return `true` to stop handling the key; `nil` otherwise.
-local function keypress(code, shift, control, alt, cmd, caps_lock)
- --print(code, M.KEYSYMS[code], shift, control, alt, cmd, caps_lock)
- if caps_lock and (shift or control or alt or cmd) and code < 256 then
+-- Handles Textadept keypresses, executing commands based on a mode or lexer as
+-- necessary.
+events.connect(events.KEYPRESS, function(code, shift, control, alt, cmd, caps)
+ --print(code, M.KEYSYMS[code], shift, control, alt, cmd, caps)
+ if caps and (shift or control or alt or cmd) and code < 256 then
code = string[shift and 'upper' or 'lower'](string.char(code)):byte()
end
local key = code >= 32 and code < 256 and string.char(code) or M.KEYSYMS[code]
@@ -216,8 +208,7 @@ local function keypress(code, shift, control, alt, cmd, caps_lock)
return true
end
-- PROPAGATE otherwise.
-end
-events.connect(events.KEYPRESS, keypress)
+end)
--[[ This comment is for LuaDoc.
---