Nest the shorter blocks instead of the longer ones.
Unified · Split
| @@ -884,37 +884,35 @@ local function handle_cursor_move() · 883 unmodified lines | ||
| 884 | 884 | end |
| 885 | 885 | |
| 886 | 886 | 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 | |
| 899 | 893 | |
| 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 | |
| 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 | 913 | end |
| 913 | 914 | |
| 914 | − handle_cursor_move() | |
| 915 | − | |
| 916 | − mp.commandv('script-message-to', input_caller, 'input-event', 'edited', | |
| 917 | − utils.format_json({line})) | |
| 915 | + render() | |
| 918 | 916 | end |
| 919 | 917 | |
| 920 | 918 | -- Insert a character at the current cursor position (any_unicode) |
| @@ -1097,7 +1095,12 @@ end · 176 unmodified lines | ||
| 1097 | 1095 | |
| 1098 | 1096 | -- Go to the specified relative position in the command history (Up, Down) |
| 1099 | 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 | 1104 | local max_lines = calculate_max_lines() |
| 1102 | 1105 | |
| 1103 | 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 | 1129 | return |
| 1127 | 1130 | end |
| 1128 | 1131 | |
| 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 | |
| 1138 | 1137 | end |
| 1139 | − | |
| 1140 | − go_history(history_pos + amount) | |
| 1138 | + render() | |
| 1141 | 1139 | end |
| 1142 | 1140 | |
| 1143 | 1141 | -- Go to the first command in the command history (PgUp) |