From 0ebd2624ae677ecd4b58c8e4abd37618ab5bb0c2 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+orbitalquark@users.noreply.github.com> Date: Mon, 12 Oct 2020 10:43:30 -0400 Subject: 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. --- modules/textadept/command_entry.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'modules/textadept/command_entry.lua') 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 @@ -34,6 +34,18 @@ local function cycle_history(prev) M:add_text(mode_history[mode_history.pos]) 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 @@ -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 -- cgit v1.2.3