aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormitchell <70453897+orbitalquark@users.noreply.github.com>2020-10-12 10:43:30 -0400
committermitchell <70453897+orbitalquark@users.noreply.github.com>2020-10-12 10:43:30 -0400
commit0ebd2624ae677ecd4b58c8e4abd37618ab5bb0c2 (patch)
tree1219185a17d354006013d29c685e1f584d1bda34 /test
parentff7f869ae0a02535dcc7f44a65dd3ea2fed87d01 (diff)
downloadtextadept-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 'test')
-rw-r--r--test/test.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/test.lua b/test/test.lua
index ec45165f..2d26293d 100644
--- a/test/test.lua
+++ b/test/test.lua
@@ -1332,6 +1332,34 @@ function test_command_entry_history()
events.emit(events.KEYPRESS, not CURSES and 0xFF1B or 7) -- esc
end
+function test_command_entry_history_append()
+ local f, keys = function() end, {['\n'] = ui.command_entry.focus}
+
+ ui.command_entry.run(f, keys)
+ ui.command_entry:set_text('foo')
+ events.emit(events.KEYPRESS, not CURSES and 0xFF0D or 343) -- \n
+
+ ui.command_entry.run(f, keys)
+ events.emit(events.KEYPRESS, not CURSES and 0xFF52 or 301) -- up
+ assert_equal(ui.command_entry:get_text(), '') -- no prior history
+ events.emit(events.KEYPRESS, not CURSES and 0xFF54 or 300) -- down
+ assert_equal(ui.command_entry:get_text(), '') -- no further history
+ events.emit(events.KEYPRESS, not CURSES and 0xFF0D or 343) -- \n
+ ui.command_entry.append_history('bar')
+
+ ui.command_entry.run(f, keys)
+ assert_equal(ui.command_entry:get_text(), 'bar')
+ assert_equal(ui.command_entry.selection_start, 1)
+ assert_equal(ui.command_entry.selection_end, 4)
+ events.emit(events.KEYPRESS, not CURSES and 0xFF52 or 301) -- up
+ assert_equal(ui.command_entry:get_text(), 'bar') -- no prior history
+ events.emit(events.KEYPRESS, not CURSES and 0xFF54 or 300) -- down
+ assert_equal(ui.command_entry:get_text(), 'bar') -- no further history
+ events.emit(events.KEYPRESS, not CURSES and 0xFF0D or 343) -- \n
+
+ assert_raises(function() ui.command_entry:append_history('text') end, 'string expected, got table')
+end
+
function test_command_entry_mode_restore()
local mode = 'test_mode'
keys.mode = mode