@@ -252,7 +252,7 @@ def reset_variables(prompt = '')
252252 @rendered_screen = RenderedScreen . new ( base_y : 0 , lines : [ ] , cursor_y : 0 )
253253 @input_lines = [ [ [ "" ] , 0 , 0 ] ]
254254 @input_lines_position = 0
255- @undoing = false
255+ @restoring = false
256256 @prev_action_state = NullActionState
257257 @next_action_state = NullActionState
258258 reset_line
@@ -1070,8 +1070,8 @@ def input_key(key)
10701070 @completion_journey_state = nil
10711071 end
10721072
1073- push_input_lines unless @undoing
1074- @undoing = false
1073+ push_input_lines unless @restoring
1074+ @restoring = false
10751075
10761076 if @in_pasting
10771077 clear_dialogs
@@ -1185,18 +1185,6 @@ def set_current_line(line, byte_pointer = nil)
11851185 process_auto_indent
11861186 end
11871187
1188- def set_current_lines ( lines , byte_pointer = nil , line_index = 0 )
1189- cursor = current_byte_pointer_cursor
1190- @buffer_of_lines = lines
1191- @line_index = line_index
1192- if byte_pointer
1193- @byte_pointer = byte_pointer
1194- else
1195- calculate_nearest_cursor ( cursor )
1196- end
1197- process_auto_indent
1198- end
1199-
12001188 def retrieve_completion_block
12011189 quote_characters = Reline . completer_quote_characters
12021190 before = current_line . byteslice ( 0 , @byte_pointer ) . grapheme_clusters
@@ -2368,24 +2356,23 @@ def finish
23682356 @config . editing_mode = :vi_insert
23692357 end
23702358
2371- private def undo ( _key )
2372- @undoing = true
2359+ private def move_undo_redo ( direction )
2360+ @restoring = true
2361+ return unless ( 0 ..@input_lines . size - 1 ) . cover? ( @input_lines_position + direction )
23732362
2374- return if @input_lines_position <= 0
2363+ @input_lines_position += direction
2364+ buffer_of_lines , byte_pointer , line_index = @input_lines [ @input_lines_position ]
2365+ @buffer_of_lines = buffer_of_lines . dup
2366+ @line_index = line_index
2367+ @byte_pointer = byte_pointer
2368+ end
23752369
2376- @input_lines_position -= 1
2377- target_lines , target_cursor_x , target_cursor_y = @input_lines [ @input_lines_position ]
2378- set_current_lines ( target_lines . dup , target_cursor_x , target_cursor_y )
2370+ private def undo ( _key )
2371+ move_undo_redo ( -1 )
23792372 end
23802373
23812374 private def redo ( _key )
2382- @undoing = true
2383-
2384- return if @input_lines_position >= @input_lines . size - 1
2385-
2386- @input_lines_position += 1
2387- target_lines , target_cursor_x , target_cursor_y = @input_lines [ @input_lines_position ]
2388- set_current_lines ( target_lines . dup , target_cursor_x , target_cursor_y )
2375+ move_undo_redo ( +1 )
23892376 end
23902377
23912378 private def prev_action_state_value ( type )
0 commit comments