aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/events.lua27
-rw-r--r--modules/textadept/editing.lua21
-rw-r--r--src/textadept.c13
3 files changed, 47 insertions, 14 deletions
diff --git a/core/events.lua b/core/events.lua
index ebd3388a..56331196 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -70,16 +70,6 @@ local M = {}
-- Arguments:
--
-- * _`byte`_: The text character's byte.
--- @field COMMAND_ENTRY_KEYPRESS (string)
--- Emitted when pressing a key in the command entry.
--- If any handler returns `true`, the key is not inserted into the entry.
--- Arguments:
---
--- * _`code`_: The numeric key code.
--- * _`shift`_: The "Shift" modifier key is held down.
--- * _`ctrl`_: The "Control" modifier key is held down.
--- * _`alt`_: The "Alt"/"Option" modifier key is held down.
--- * _`meta`_: The "Command" modifier key on Mac OSX is held down.
-- @field DOUBLE_CLICK (string)
-- Emitted after double-clicking the mouse button.
-- Arguments:
@@ -91,6 +81,15 @@ local M = {}
-- Note: If you set `buffer.rectangular_selection_modifier` to
-- `buffer.MOD_CTRL`, the "Control" modifier is reported as *both* "Control"
-- and "Alt" due to a Scintilla limitation with GTK+.
+-- @field CSI (string)
+-- Emitted when the terminal version receives an unrecognized CSI sequence.
+-- Arguments:
+--
+-- * _`cmd`_: The 24-bit CSI command value. The lowest byte contains the
+-- command byte. The second lowest byte contains the leading byte, if any
+-- (e.g. '?'). The third lowest byte contains the intermediate byte, if any
+-- (e.g. '$').
+-- * _`args`_: Table of numeric arguments of the CSI sequence.
-- @field DWELL_END (string)
-- Emitted after `DWELL_START` when the user moves the mouse, presses a key,
-- or scrolls the view.
@@ -366,10 +365,10 @@ end)
for _, n in pairs(scnotifications) do M[n[1]:upper()] = n[1] end
local ta_events = {
'appleevent_odoc', 'buffer_after_switch', 'buffer_before_switch',
- 'buffer_deleted', 'buffer_new', 'command_entry_command',
- 'command_entry_keypress', 'error', 'find', 'focus', 'initialized', 'keypress',
- 'menu_clicked', 'quit', 'replace', 'replace_all', 'reset_after',
- 'reset_before', 'view_after_switch', 'view_before_switch', 'view_new'
+ 'buffer_deleted', 'buffer_new', 'csi', 'error', 'find', 'focus',
+ 'initialized', 'keypress', 'menu_clicked', 'quit', 'replace', 'replace_all',
+ 'reset_after', 'reset_before', 'view_after_switch', 'view_before_switch',
+ 'view_new'
}
for _, e in pairs(ta_events) do M[e:upper()] = e end
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index ce93dd54..cfc03f73 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -193,6 +193,27 @@ events.connect(events.CHAR_ADDED, function(char)
end
end)
+-- Enables and disables bracketed paste mode in curses and disables auto-pair
+-- and auto-indent while pasting.
+if CURSES and not WIN32 then
+ io.stdout:write('\x1b[?2004h') -- enable bracketed paste mode
+ io.stdout:flush()
+ events.connect(events.QUIT, function()
+ io.stdout:write('\x1b[?2004l') -- disable bracketed paste mode
+ io.stdout:flush()
+ end, 1)
+ local reenable_autopair, reenable_autoindent
+ events.connect('csi', function(cmd, args)
+ if cmd ~= string.byte('~') then return end
+ if args[1] == 200 then
+ reenable_autopair, M.AUTOPAIR = M.AUTOPAIR, false
+ reenable_autoindent, M.AUTOINDENT = M.AUTOINDENT, false
+ elseif args[1] == 201 then
+ M.AUTOPAIR, M.AUTOINDENT = reenable_autopair, reenable_autoindent
+ end
+ end)
+end
+
-- Prepares the buffer for saving to a file.
events.connect(events.FILE_BEFORE_SAVE, function()
if not M.STRIP_TRAILING_SPACES then return end
diff --git a/src/textadept.c b/src/textadept.c
index 86d457d1..4d433087 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -2409,6 +2409,19 @@ int main(int argc, char **argv) {
else if (key.type == TERMKEY_TYPE_KEYSYM &&
key.code.sym >= 0 && key.code.sym <= TERMKEY_SYM_END)
c = keysyms[key.code.sym];
+ else if (key.type == TERMKEY_TYPE_UNKNOWN_CSI) {
+ long args[16];
+ size_t nargs = 16;
+ unsigned long cmd;
+ termkey_interpret_csi(ta_tk, &key, args, &nargs, &cmd);
+ lua_newtable(lua);
+ for (int i = 0; i < nargs; i++)
+ lua_pushinteger(lua, args[i]), lua_rawseti(lua, -2, i + 1);
+ lL_event(lua, "csi", LUA_TNUMBER, cmd, LUA_TTABLE,
+ luaL_ref(lua, LUA_REGISTRYINDEX), -1);
+ refresh_all();
+ continue;
+ } else continue; // skip unknown types
int shift = key.modifiers & TERMKEY_KEYMOD_SHIFT;
int ctrl = key.modifiers & TERMKEY_KEYMOD_CTRL;
int alt = key.modifiers & TERMKEY_KEYMOD_ALT;