diff options
-rw-r--r-- | core/events.lua | 4 | ||||
-rw-r--r-- | core/keys.lua | 2 | ||||
-rw-r--r-- | modules/textadept/command_entry.lua | 1 | ||||
-rw-r--r-- | modules/textadept/find.lua | 17 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 2 | ||||
-rw-r--r-- | src/textadept.c | 14 |
6 files changed, 24 insertions, 16 deletions
diff --git a/core/events.lua b/core/events.lua index 3ee2e333..0953f2f1 100644 --- a/core/events.lua +++ b/core/events.lua @@ -67,11 +67,14 @@ local M = {} -- * `ch`: The text character byte. -- @field COMMAND_ENTRY_COMMAND (string) -- Called when a command is entered into the Command Entry. +-- If any handler returns `true`, the Command Entry does not hide +-- automatically. -- Arguments: -- -- * `command`: The command text. -- @field COMMAND_ENTRY_KEYPRESS (string) -- Called when a key is pressed in the Command Entry. +-- If any handler returns `true`, the key is not inserted into the entry. -- Arguments: -- -- * `code`: The key code. @@ -176,6 +179,7 @@ local M = {} -- * `position`: The text position of the release. -- @field KEYPRESS (string) -- Called when a key is pressed. +-- If any handler returns `true`, the key is not inserted into the buffer. -- Arguments: -- -- * `code`: The key code. diff --git a/core/keys.lua b/core/keys.lua index 65042fe0..40502501 100644 --- a/core/keys.lua +++ b/core/keys.lua @@ -111,6 +111,8 @@ local error = function(e) events.emit(events.ERROR, e) end -- @class table -- @name KEYSYMS M.KEYSYMS = { + -- From ncurses.h + [263] = '\b', -- From Scintilla.h. [300] = 'down', [301] = 'up', [302] = 'left', [303] = 'right', [304] = 'home', [305] = 'end', diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua index 262444d6..c1673217 100644 --- a/modules/textadept/command_entry.lua +++ b/modules/textadept/command_entry.lua @@ -43,7 +43,6 @@ end) events.connect(events.COMMAND_ENTRY_KEYPRESS, function(code) if keys.KEYSYMS[code] == 'esc' then gui.command_entry.focus() -- toggle focus to hide - return true elseif not NCURSES and keys.KEYSYMS[code] == '\t' or code == 9 then local substring = gui.command_entry.entry_text:match('[%w_.:]+$') or '' local path, o, prefix = substring:match('^([%w_.:]-)([.:]?)([%w_]*)$') diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index 279a7adb..20dba7c4 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -233,16 +233,13 @@ function find.find_incremental() end events_connect(events.COMMAND_ENTRY_KEYPRESS, function(code) - if find.incremental then - if keys.KEYSYMS[code] == 'esc' then - find.incremental = nil - elseif code < 256 or keys.KEYSYMS[code] == '\b' then - if keys.KEYSYMS[code] == '\b' then - find_incremental(gui.command_entry.entry_text:sub(1, -2)) - else - find_incremental(gui.command_entry.entry_text..string.char(code)) - end - end + if not find.incremental then return end + if not NCURSES and keys.KEYSYMS[code] == 'esc' or code == 27 then + find.incremental = nil + elseif keys.KEYSYMS[code] == '\b' then + find_incremental(gui.command_entry.entry_text:sub(1, -2)) + elseif code < 256 then + find_incremental(gui.command_entry.entry_text..string.char(code)) end end, 1) -- place before command_entry.lua's handler (if necessary) diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index c7a2aa0c..a4a23406 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -180,7 +180,7 @@ local M = {} -- Bksp |⌫<br/>⇧⌫ |^H<br/>Bksp |Delete back -- Ctrl+Bksp |⌘⌫ |None |Delete word left -- Ctrl+Shift+Bksp |⌘⇧⌫ |None |Delete line left --- Tab |⇥ |Tab |Insert tab or indent +-- Tab |⇥ |Tab<br/>^I |Insert tab or indent -- Shift+Tab |⇧⇥ |S-Tab |Dedent -- None |^K |^K |Cut to line end -- None |^L |None |Center line vertically diff --git a/src/textadept.c b/src/textadept.c index c5564dc5..1611b9b9 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -540,13 +540,18 @@ static int lfind__newindex(lua_State *L) { #if NCURSES /** * Signal for a keypress inside the Command Entry. + * As a BINDFN, returns `TRUE` to stop key propagation. + * As a PROCESSFN, returns `TRUE` to continue key propagation. */ -static int c_keypress(EObjectType _, void *object, void *__, chtype key) { +static int c_keypress(EObjectType _, void *object, void *data, chtype key) { + if (data && (key == KEY_ENTER || key == KEY_TAB)) return TRUE; + int ret = TRUE; if (key == KEY_ENTER) { fcopy(&command_text, getCDKEntryValue((CDKENTRY *)object)); - lL_event(lua, "command_entry_command", LUA_TSTRING, command_text, -1); - } else lL_event(lua, "command_entry_keypress", LUA_TNUMBER, '\t', -1); - return key == KEY_TAB; + ret = lL_event(lua, "command_entry_command", LUA_TSTRING, command_text, -1); + } else ret = !lL_event(lua, "command_entry_keypress", LUA_TNUMBER, key, -1); + scintilla_refresh(focused_view), drawCDKEntry((CDKENTRY *)object, FALSE); + return key == KEY_TAB || ret; } #endif @@ -567,6 +572,7 @@ static int lce_focus(lua_State *L) { vMIXED, 0, 0, 256, FALSE, FALSE); bindCDKObject(vENTRY, command_entry, KEY_TAB, c_keypress, NULL); bindCDKObject(vENTRY, command_entry, KEY_ENTER, c_keypress, NULL); + setCDKEntryPreProcess(command_entry, c_keypress, ""); setCDKEntryValue(command_entry, command_text); char *clipboard = get_clipboard(); GPasteBuffer = copyChar(clipboard); // set the CDK paste buffer |