History

console.lua: reduce indentation in 2 functions

Nest the shorter blocks instead of the longer ones.

Guido Cella committed 1 year ago

Commit a8397381 parent b23bd341 file · +36 −38Browse files

Unified · Split

player/lua/console.lua+36−38
@@ -884,37 +884,35 @@ local function handle_cursor_move() · 883 unmodified lines
884884 end
885885
886886 local function handle_edit()
887− if selectable_items then
888− matches = {}
889− for i, match in ipairs(fuzzy_find(line, selectable_items)) do
890− matches[i] = {
891− index = match[1],
892− text = selectable_items[match[1]],
893− positions = match[2],
894− }
895− end
896−
897− if line == '' and default_item then
898− selected_match = default_item
887+ if not selectable_items then
888+ handle_cursor_move()
889+ mp.commandv('script-message-to', input_caller, 'input-event', 'edited',
890+ utils.format_json({line}))
891+ return
892+ end
899893
900− local max_lines = calculate_max_lines()
901− first_match_to_print = math.max(1, selected_match + 1 - math.ceil(max_lines / 2))
902− if first_match_to_print > #selectable_items - max_lines + 1 then
903− first_match_to_print = math.max(1, #selectable_items - max_lines + 1)
904− end
905− else
906− selected_match = 1
907− end
894+ matches = {}
895+ for i, match in ipairs(fuzzy_find(line, selectable_items)) do
896+ matches[i] = {
897+ index = match[1],
898+ text = selectable_items[match[1]],
899+ positions = match[2],
900+ }
901+ end
908902
909− render()
903+ if line == '' and default_item then
904+ selected_match = default_item
910905
911− return
906+ local max_lines = calculate_max_lines()
907+ first_match_to_print = math.max(1, selected_match + 1 - math.ceil(max_lines / 2))
908+ if first_match_to_print > #selectable_items - max_lines + 1 then
909+ first_match_to_print = math.max(1, #selectable_items - max_lines + 1)
910+ end
911+ else
912+ selected_match = 1
912913 end
913914
914− handle_cursor_move()
915−
916− mp.commandv('script-message-to', input_caller, 'input-event', 'edited',
917− utils.format_json({line}))
915+ render()
918916 end
919917
920918 -- Insert a character at the current cursor position (any_unicode)
@@ -1097,7 +1095,12 @@ end · 176 unmodified lines
10971095
10981096 -- Go to the specified relative position in the command history (Up, Down)
10991097 local function move_history(amount, is_wheel)
1100− if is_wheel and selectable_items then
1098+ if not selectable_items then
1099+ go_history(history_pos + amount)
1100+ return
1101+ end
1102+
1103+ if is_wheel then
11011104 local max_lines = calculate_max_lines()
11021105
11031106 -- Update selected_match only if it's the first or last printed item and
@@ -1126,18 +1129,13 @@ local function move_history(amount, is_wheel) · 22 unmodified lines
11261129 return
11271130 end
11281131
1129− if selectable_items then
1130− selected_match = selected_match + amount
1131− if selected_match > #matches then
1132− selected_match = 1
1133− elseif selected_match < 1 then
1134− selected_match = #matches
1135− end
1136− render()
1137− return
1132+ selected_match = selected_match + amount
1133+ if selected_match > #matches then
1134+ selected_match = 1
1135+ elseif selected_match < 1 then
1136+ selected_match = #matches
11381137 end
1139−
1140− go_history(history_pos + amount)
1138+ render()
11411139 end
11421140
11431141 -- Go to the first command in the command history (PgUp)

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