diff options
author | 2020-05-24 15:39:17 -0400 | |
---|---|---|
committer | 2020-05-24 15:39:17 -0400 | |
commit | effc636745e8d9c680c3acf42e8e25eed10cd903 (patch) | |
tree | cc6ba82e3f7fb23ff73281af03d462ffd4c24e77 | |
parent | 426e323063217b4395dd1871392d3df13c30ed4f (diff) | |
download | textadept-effc636745e8d9c680c3acf42e8e25eed10cd903.tar.gz textadept-effc636745e8d9c680c3acf42e8e25eed10cd903.zip |
Restore prior key mode after running the command entry.
-rw-r--r-- | modules/textadept/command_entry.lua | 5 | ||||
-rw-r--r-- | test/test.lua | 10 |
2 files changed, 14 insertions, 1 deletions
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua index 86f65ba5..29bea5b0 100644 --- a/modules/textadept/command_entry.lua +++ b/modules/textadept/command_entry.lua @@ -162,6 +162,8 @@ end -- @name lua_keys local lua_keys = {['\t'] = complete_lua} +local prev_key_mode + --- -- Opens the command entry, subjecting it to any key bindings defined in table -- *keys*, highlighting text with lexer name *lexer*, and displaying @@ -217,6 +219,7 @@ function M.run(f, keys, lexer, height) local mode_history = history[history.mode] M:set_text(mode_history and mode_history[mode_history.pos] or '') M:select_all() + prev_key_mode = _G.keys.mode M.focus() M:set_lexer(lexer or 'text') M.height = M:text_height(1) * (height or 1) @@ -226,7 +229,7 @@ end -- Redefine ui.command_entry.focus() to clear any current key mode on hide/show. local orig_focus = M.focus M.focus = function() - keys.mode = nil + keys.mode = prev_key_mode orig_focus() end diff --git a/test/test.lua b/test/test.lua index e67f02ae..b27329fa 100644 --- a/test/test.lua +++ b/test/test.lua @@ -1242,6 +1242,16 @@ function test_command_entry_history() events.emit(events.KEYPRESS, not CURSES and 0xFF1B or 7) -- esc end +function test_command_entry_mode_restore() + local mode = 'test_mode' + keys.mode = mode + ui.command_entry.run(nil) + assert(keys.mode ~= mode) + events.emit(events.KEYPRESS, not CURSES and 0xFF0D or 343) -- \n + assert_equal(keys.mode, mode) + keys.mode = nil +end + function test_editing_auto_pair() buffer.new() -- Single selection. |