Nest the shorter blocks instead of the longer ones.
Unified · Split
| @@ -884,37 +884,35 @@ local function handle_cursor_move() · 883 unmodified lines | |||
| 884 | end | 884 | end |
| 885 | 885 | ||
| 886 | local function handle_edit() | 886 | local function handle_edit() |
| 887 | if selectable_items then | 887 | if not selectable_items then |
| 888 | matches = {} | 888 | handle_cursor_move() |
| 889 | for i, match in ipairs(fuzzy_find(line, selectable_items)) do | 889 | 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 then | 896 | matches[i] = { |
| 903 | first_match_to_print = math.max(1, #selectable_items - max_lines + 1) | 897 | index = match[1], |
| 904 | end | 898 | text = selectable_items[match[1]], |
| 905 | else | 899 | positions = match[2], |
| 906 | selected_match = 1 | 900 | } |
| 907 | end | 901 | end |
| 908 | 902 | ||
| 909 | render() | 903 | if line == '' and default_item then |
| 904 | selected_match = default_item | ||
| 910 | 905 | ||
| 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 | ||
| 912 | end | 913 | 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})) | ||
| 918 | end | 916 | end |
| 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) |
| 1099 | local function move_history(amount, is_wheel) | 1097 | 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 | ||
| 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 and | 1106 | -- 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 | return | 1129 | return |
| 1127 | end | 1130 | end |
| 1128 | 1131 | ||
| 1129 | if selectable_items then | 1132 | selected_match = selected_match + amount |
| 1130 | selected_match = selected_match + amount | 1133 | if selected_match > #matches then |
| 1131 | if selected_match > #matches then | 1134 | selected_match = 1 |
| 1132 | selected_match = 1 | 1135 | elseif selected_match < 1 then |
| 1133 | elseif selected_match < 1 then | 1136 | selected_match = #matches |
| 1134 | selected_match = #matches | ||
| 1135 | end | ||
| 1136 | render() | ||
| 1137 | return | ||
| 1138 | end | 1137 | end |
| 1139 | 1138 | render() | |
| 1140 | go_history(history_pos + amount) | ||
| 1141 | end | 1139 | end |
| 1142 | 1140 | ||
| 1143 | -- Go to the first command in the command history (PgUp) | 1141 | -- Go to the first command in the command history (PgUp) |