@@ -252,7 +252,7 @@ def reset_variables(prompt = '')
252
252
@rendered_screen = RenderedScreen . new ( base_y : 0 , lines : [ ] , cursor_y : 0 )
253
253
@input_lines = [ [ [ "" ] , 0 , 0 ] ]
254
254
@input_lines_position = 0
255
- @undoing = false
255
+ @restoring = false
256
256
@prev_action_state = NullActionState
257
257
@next_action_state = NullActionState
258
258
reset_line
@@ -1070,8 +1070,8 @@ def input_key(key)
1070
1070
@completion_journey_state = nil
1071
1071
end
1072
1072
1073
- push_input_lines unless @undoing
1074
- @undoing = false
1073
+ push_input_lines unless @restoring
1074
+ @restoring = false
1075
1075
1076
1076
if @in_pasting
1077
1077
clear_dialogs
@@ -1185,18 +1185,6 @@ def set_current_line(line, byte_pointer = nil)
1185
1185
process_auto_indent
1186
1186
end
1187
1187
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
-
1200
1188
def retrieve_completion_block
1201
1189
quote_characters = Reline . completer_quote_characters
1202
1190
before = current_line . byteslice ( 0 , @byte_pointer ) . grapheme_clusters
@@ -2368,24 +2356,23 @@ def finish
2368
2356
@config . editing_mode = :vi_insert
2369
2357
end
2370
2358
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 )
2373
2362
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
2375
2369
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 )
2379
2372
end
2380
2373
2381
2374
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 )
2389
2376
end
2390
2377
2391
2378
private def prev_action_state_value ( type )
0 commit comments