History

console.lua: don't duplicate the check to add to history

Guido Cella committed 1 year ago

Commit 6f2ce8a1 parent 0b3cc3a1 file · +6 −4Browse files

Unified · Split

player/lua/console.lua+6−4
@@ -873,6 +873,10 @@ end · 872 unmodified lines
873 873
874-- Add a line to the history and deduplicate874-- Add a line to the history and deduplicate
875local function history_add(text)875local function history_add(text)
876 if history[#history] == text or text == '' then
877 return
878 end
879
876 if opts.history_dedup then880 if opts.history_dedup then
877 -- More recent entries are more likely to be repeated881 -- More recent entries are more likely to be repeated
878 for i = #history, 1, -1 do882 for i = #history, 1, -1 do
@@ -1028,9 +1032,7 @@ local function submit() · 149 unmodified lines
1028 mp.commandv('script-message-to', input_caller, 'input-event', 'submit',1032 mp.commandv('script-message-to', input_caller, 'input-event', 'submit',
1029 utils.format_json({line}))1033 utils.format_json({line}))
1030 1034
1031 if history[#history] ~= line and line ~= '' then1035 history_add(line)
1032 history_add(line)
1033 end
1034 end1036 end
1035 1037
1036 if not keep_open then1038 if not keep_open then
@@ -1100,7 +1102,7 @@ local function go_history(new_pos) · 63 unmodified lines
1100 -- If the user was editing a non-history line, save it as the last history1102 -- If the user was editing a non-history line, save it as the last history
1101 -- entry. This makes it much less frustrating to accidentally hit Up/Down1103 -- entry. This makes it much less frustrating to accidentally hit Up/Down
1102 -- while editing a line.1104 -- while editing a line.
1103 if old_pos == #history + 1 and line ~= '' and history[#history] ~= line then1105 if old_pos == #history + 1 then
1104 history_add(line)1106 history_add(line)
1105 end1107 end
1106 1108

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t