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
884end884end
885 885
886local function handle_edit()886local function handle_edit()
887 if selectable_items then887 if not selectable_items then
888 matches = {}888 handle_cursor_move()
889 for i, match in ipairs(fuzzy_find(line, selectable_items)) do889 mp.commandv('script-message-to', input_caller, 'input-event', 'edited',
890 matches[i] = {890 utils.format_json({line}))
891 index = match[1],891 return
892 text = selectable_items[match[1]],892 end
893 positions = match[2],
894 }
895 end
896
897 if line == '' and default_item then
898 selected_match = default_item
899 893
900 local max_lines = calculate_max_lines()894 matches = {}
901 first_match_to_print = math.max(1, selected_match + 1 - math.ceil(max_lines / 2))895 for i, match in ipairs(fuzzy_find(line, selectable_items)) do
902 if first_match_to_print > #selectable_items - max_lines + 1 then896 matches[i] = {
903 first_match_to_print = math.max(1, #selectable_items - max_lines + 1)897 index = match[1],
904 end898 text = selectable_items[match[1]],
905 else899 positions = match[2],
906 selected_match = 1900 }
907 end901 end
908 902
909 render()903 if line == '' and default_item then
904 selected_match = default_item
910 905
911 return906 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
912 end913 end
913 914
914 handle_cursor_move()915 render()
915
916 mp.commandv('script-message-to', input_caller, 'input-event', 'edited',
917 utils.format_json({line}))
918end916end
919 917
920-- Insert a character at the current cursor position (any_unicode)918-- Insert a character at the current cursor position (any_unicode)
@@ -1097,7 +1095,12 @@ end · 176 unmodified lines
1097 1095
1098-- Go to the specified relative position in the command history (Up, Down)1096-- Go to the specified relative position in the command history (Up, Down)
1099local function move_history(amount, is_wheel)1097local function move_history(amount, is_wheel)
1100 if is_wheel and selectable_items then1098 if not selectable_items then
1099 go_history(history_pos + amount)
1100 return
1101 end
1102
1103 if is_wheel then
1101 local max_lines = calculate_max_lines()1104 local max_lines = calculate_max_lines()
1102 1105
1103 -- Update selected_match only if it's the first or last printed item and1106 -- 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
1126 return1129 return
1127 end1130 end
1128 1131
1129 if selectable_items then1132 selected_match = selected_match + amount
1130 selected_match = selected_match + amount1133 if selected_match > #matches then
1131 if selected_match > #matches then1134 selected_match = 1
1132 selected_match = 11135 elseif selected_match < 1 then
1133 elseif selected_match < 1 then1136 selected_match = #matches
1134 selected_match = #matches
1135 end
1136 render()
1137 return
1138 end1137 end
1139 1138 render()
1140 go_history(history_pos + amount)
1141end1139end
1142 1140
1143-- Go to the first command in the command history (PgUp)1141-- 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