diff options
author | 2020-10-12 10:43:30 -0400 | |
---|---|---|
committer | 2020-10-12 10:43:30 -0400 | |
commit | 0ebd2624ae677ecd4b58c8e4abd37618ab5bb0c2 (patch) | |
tree | 1219185a17d354006013d29c685e1f584d1bda34 /modules/textadept/command_entry.lua | |
parent | ff7f869ae0a02535dcc7f44a65dd3ea2fed87d01 (diff) | |
download | textadept-0ebd2624ae677ecd4b58c8e4abd37618ab5bb0c2.tar.gz textadept-0ebd2624ae677ecd4b58c8e4abd37618ab5bb0c2.zip |
Added `ui.command_entry.append_history()` for manually appending history.
Normally history is auto-appended by the default '\n' key handler, but some
custom modes may have their own '\n' handlers and did not have a way to append
history.
Diffstat (limited to 'modules/textadept/command_entry.lua')
-rw-r--r-- | modules/textadept/command_entry.lua | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua index 594b1e81..5c30394e 100644 --- a/modules/textadept/command_entry.lua +++ b/modules/textadept/command_entry.lua @@ -35,6 +35,18 @@ local function cycle_history(prev) end --- +-- Appends the given text to the history for the current or most recent command +-- entry mode. +-- @param text String text to append to history. +-- @name append_history +function M.append_history(text) + if not history.mode then return end + local mode_history = history[history.mode] + mode_history[#mode_history + 1] = assert_type(text, 'string', 1) + mode_history.pos = #mode_history +end + +--- -- A metatable with typical platform-specific key bindings for text entries. -- This metatable may be used to add basic editing and movement keys to command -- entry modes. It is automatically added to command entry modes unless a @@ -217,9 +229,7 @@ function M.run(f, keys, lang, height) if M:auto_c_active() then return false end -- allow Enter to autocomplete M.focus() -- hide if not f then return end - local mode_history = history[history.mode] - mode_history[#mode_history + 1] = M:get_text() - mode_history.pos = #mode_history + M.append_history(M:get_text()) f(M:get_text()) end end |