aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/textadept/command_entry.lua4
-rw-r--r--test/test.lua9
2 files changed, 4 insertions, 9 deletions
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua
index c2b6d7f6..86f65ba5 100644
--- a/modules/textadept/command_entry.lua
+++ b/modules/textadept/command_entry.lua
@@ -207,7 +207,7 @@ function M.run(f, keys, lexer, height)
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 + 1
+ mode_history.pos = #mode_history
f(M:get_text())
end
end
@@ -215,7 +215,7 @@ function M.run(f, keys, lexer, height)
if f and not history[f] then history[f] = {pos = 0} end
history.mode = f
local mode_history = history[history.mode]
- M:set_text(mode_history and mode_history[#mode_history] or '')
+ M:set_text(mode_history and mode_history[mode_history.pos] or '')
M:select_all()
M.focus()
M:set_lexer(lexer or 'text')
diff --git a/test/test.lua b/test/test.lua
index 1d920f6e..e67f02ae 100644
--- a/test/test.lua
+++ b/test/test.lua
@@ -1212,9 +1212,9 @@ function test_command_entry_history()
events.emit(events.KEYPRESS, not CURSES and 0xFF0D or 343) -- \n
ui.command_entry.run(one)
- assert_equal(ui.command_entry:get_text(), '')
- events.emit(events.KEYPRESS, not CURSES and 0xFF52 or 301) -- up
assert_equal(ui.command_entry:get_text(), 'foo')
+ 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(), 'foo') -- no prior history
events.emit(events.KEYPRESS, not CURSES and 0xFF54 or 300) -- down
@@ -1224,8 +1224,6 @@ function test_command_entry_history()
ui.command_entry.run(one)
events.emit(events.KEYPRESS, not CURSES and 0xFF52 or 301) -- up
- assert_equal(ui.command_entry:get_text(), 'baz')
- events.emit(events.KEYPRESS, not CURSES and 0xFF52 or 301) -- up
assert_equal(ui.command_entry:get_text(), 'foo')
events.emit(events.KEYPRESS, not CURSES and 0xFF54 or 300) -- down
assert_equal(ui.command_entry:get_text(), 'baz')
@@ -1234,15 +1232,12 @@ function test_command_entry_history()
ui.command_entry.run(one)
events.emit(events.KEYPRESS, not CURSES and 0xFF52 or 301) -- up
- assert_equal(ui.command_entry:get_text(), 'foo')
- events.emit(events.KEYPRESS, not CURSES and 0xFF52 or 301) -- up
assert_equal(ui.command_entry:get_text(), 'baz')
events.emit(events.KEYPRESS, not CURSES and 0xFF52 or 301) -- up
assert_equal(ui.command_entry:get_text(), 'foo')
events.emit(events.KEYPRESS, not CURSES and 0xFF1B or 7) -- esc
ui.command_entry.run(two)
- events.emit(events.KEYPRESS, not CURSES and 0xFF52 or 301) -- up
assert_equal(ui.command_entry:get_text(), 'bar')
events.emit(events.KEYPRESS, not CURSES and 0xFF1B or 7) -- esc
end