@@ -229,8 +229,8 @@ def reset_variables(prompt = '', encoding:)
229
229
@vi_clipboard = ''
230
230
@vi_arg = nil
231
231
@waiting_proc = nil
232
- @waiting_operator_proc = nil
233
- @waiting_operator_vi_arg = nil
232
+ @vi_waiting_operator = nil
233
+ @vi_waiting_operator_arg = nil
234
234
@completion_journey_state = nil
235
235
@completion_state = CompletionState ::NORMAL
236
236
@completion_occurs = false
@@ -936,37 +936,23 @@ def dialog_proc_scope_completion_journey_data
936
936
end
937
937
938
938
private def run_for_operators ( key , method_symbol , &block )
939
- if @waiting_operator_proc
939
+ if @vi_waiting_operator
940
940
if VI_MOTIONS . include? ( method_symbol )
941
941
old_byte_pointer = @byte_pointer
942
- @vi_arg = @waiting_operator_vi_arg if @waiting_operator_vi_arg &.> 1
942
+ @vi_arg = ( @vi_arg || 1 ) * @vi_waiting_operator_arg
943
943
block . ( true )
944
944
unless @waiting_proc
945
945
byte_pointer_diff = @byte_pointer - old_byte_pointer
946
946
@byte_pointer = old_byte_pointer
947
- @waiting_operator_proc . ( byte_pointer_diff )
948
- else
949
- old_waiting_proc = @waiting_proc
950
- old_waiting_operator_proc = @waiting_operator_proc
951
- current_waiting_operator_proc = @waiting_operator_proc
952
- @waiting_proc = proc { |k |
953
- old_byte_pointer = @byte_pointer
954
- old_waiting_proc . ( k )
955
- byte_pointer_diff = @byte_pointer - old_byte_pointer
956
- @byte_pointer = old_byte_pointer
957
- current_waiting_operator_proc . ( byte_pointer_diff )
958
- @waiting_operator_proc = old_waiting_operator_proc
959
- }
947
+ send ( @vi_waiting_operator , byte_pointer_diff )
948
+ cleanup_waiting
960
949
end
961
950
else
962
951
# Ignores operator when not motion is given.
963
952
block . ( false )
953
+ cleanup_waiting
964
954
end
965
- @waiting_operator_proc = nil
966
- @waiting_operator_vi_arg = nil
967
- if @vi_arg
968
- @vi_arg = nil
969
- end
955
+ @vi_arg = nil
970
956
else
971
957
block . ( false )
972
958
end
@@ -983,7 +969,7 @@ def dialog_proc_scope_completion_journey_data
983
969
end
984
970
985
971
def wrap_method_call ( method_symbol , method_obj , key , with_operator = false )
986
- if @config . editing_mode_is? ( :emacs , :vi_insert ) and @waiting_proc . nil? and @waiting_operator_proc . nil?
972
+ if @config . editing_mode_is? ( :emacs , :vi_insert ) and @vi_waiting_operator . nil?
987
973
not_insertion = method_symbol != :ed_insert
988
974
process_insert ( force : not_insertion )
989
975
end
@@ -1002,11 +988,32 @@ def wrap_method_call(method_symbol, method_obj, key, with_operator = false)
1002
988
end
1003
989
end
1004
990
991
+ private def cleanup_waiting
992
+ @waiting_proc = nil
993
+ @vi_waiting_operator = nil
994
+ @vi_waiting_operator_arg = nil
995
+ @searching_prompt = nil
996
+ @drop_terminate_spaces = false
997
+ end
998
+
1005
999
private def process_key ( key , method_symbol )
1000
+ if key . is_a? ( Symbol )
1001
+ cleanup_waiting
1002
+ elsif @waiting_proc
1003
+ old_byte_pointer = @byte_pointer
1004
+ @waiting_proc . call ( key )
1005
+ if @vi_waiting_operator
1006
+ byte_pointer_diff = @byte_pointer - old_byte_pointer
1007
+ @byte_pointer = old_byte_pointer
1008
+ send ( @vi_waiting_operator , byte_pointer_diff )
1009
+ cleanup_waiting
1010
+ end
1011
+ @kill_ring . process
1012
+ return
1013
+ end
1014
+
1006
1015
if method_symbol and respond_to? ( method_symbol , true )
1007
1016
method_obj = method ( method_symbol )
1008
- else
1009
- method_obj = nil
1010
1017
end
1011
1018
if method_symbol and key . is_a? ( Symbol )
1012
1019
if @vi_arg and argumentable? ( method_obj )
@@ -1028,8 +1035,6 @@ def wrap_method_call(method_symbol, method_obj, key, with_operator = false)
1028
1035
run_for_operators ( key , method_symbol ) do |with_operator |
1029
1036
wrap_method_call ( method_symbol , method_obj , key , with_operator )
1030
1037
end
1031
- elsif @waiting_proc
1032
- @waiting_proc . ( key )
1033
1038
elsif method_obj
1034
1039
wrap_method_call ( method_symbol , method_obj , key )
1035
1040
else
@@ -1040,9 +1045,6 @@ def wrap_method_call(method_symbol, method_obj, key, with_operator = false)
1040
1045
@vi_arg = nil
1041
1046
end
1042
1047
end
1043
- elsif @waiting_proc
1044
- @waiting_proc . ( key )
1045
- @kill_ring . process
1046
1048
elsif method_obj
1047
1049
if method_symbol == :ed_argument_digit
1048
1050
wrap_method_call ( method_symbol , method_obj , key )
@@ -2325,46 +2327,63 @@ def finish
2325
2327
@byte_pointer = 0
2326
2328
end
2327
2329
2328
- private def vi_change_meta ( key , arg : 1 )
2329
- @drop_terminate_spaces = true
2330
- @waiting_operator_proc = proc { |byte_pointer_diff |
2331
- if byte_pointer_diff > 0
2332
- line , cut = byteslice! ( current_line , @byte_pointer , byte_pointer_diff )
2333
- elsif byte_pointer_diff < 0
2334
- line , cut = byteslice! ( current_line , @byte_pointer + byte_pointer_diff , -byte_pointer_diff )
2335
- end
2336
- set_current_line ( line )
2337
- copy_for_vi ( cut )
2338
- @byte_pointer += byte_pointer_diff if byte_pointer_diff < 0
2339
- @config . editing_mode = :vi_insert
2340
- @drop_terminate_spaces = false
2341
- }
2342
- @waiting_operator_vi_arg = arg
2330
+ private def vi_change_meta ( key , arg : nil )
2331
+ if @vi_waiting_operator
2332
+ set_current_line ( '' , 0 ) if @vi_waiting_operator == :vi_change_meta_confirm && arg . nil?
2333
+ @vi_waiting_operator = nil
2334
+ @vi_waiting_operator_arg = nil
2335
+ else
2336
+ @drop_terminate_spaces = true
2337
+ @vi_waiting_operator = :vi_change_meta_confirm
2338
+ @vi_waiting_operator_arg = arg || 1
2339
+ end
2343
2340
end
2344
2341
2345
- private def vi_delete_meta ( key , arg : 1 )
2346
- @waiting_operator_proc = proc { |byte_pointer_diff |
2347
- if byte_pointer_diff > 0
2348
- line , cut = byteslice! ( current_line , @byte_pointer , byte_pointer_diff )
2349
- elsif byte_pointer_diff < 0
2350
- line , cut = byteslice! ( current_line , @byte_pointer + byte_pointer_diff , -byte_pointer_diff )
2351
- end
2352
- copy_for_vi ( cut )
2353
- set_current_line ( line || '' , @byte_pointer + ( byte_pointer_diff < 0 ? byte_pointer_diff : 0 ) )
2354
- }
2355
- @waiting_operator_vi_arg = arg
2342
+ private def vi_change_meta_confirm ( byte_pointer_diff )
2343
+ vi_delete_meta_confirm ( byte_pointer_diff )
2344
+ @config . editing_mode = :vi_insert
2345
+ @drop_terminate_spaces = false
2356
2346
end
2357
2347
2358
- private def vi_yank ( key , arg : 1 )
2359
- @waiting_operator_proc = proc { |byte_pointer_diff |
2360
- if byte_pointer_diff > 0
2361
- cut = current_line . byteslice ( @byte_pointer , byte_pointer_diff )
2362
- elsif byte_pointer_diff < 0
2363
- cut = current_line . byteslice ( @byte_pointer + byte_pointer_diff , -byte_pointer_diff )
2364
- end
2365
- copy_for_vi ( cut )
2366
- }
2367
- @waiting_operator_vi_arg = arg
2348
+ private def vi_delete_meta ( key , arg : nil )
2349
+ if @vi_waiting_operator
2350
+ set_current_line ( '' , 0 ) if @vi_waiting_operator == :vi_delete_meta_confirm && arg . nil?
2351
+ @vi_waiting_operator = nil
2352
+ @vi_waiting_operator_arg = nil
2353
+ else
2354
+ @vi_waiting_operator = :vi_delete_meta_confirm
2355
+ @vi_waiting_operator_arg = arg || 1
2356
+ end
2357
+ end
2358
+
2359
+ private def vi_delete_meta_confirm ( byte_pointer_diff )
2360
+ if byte_pointer_diff > 0
2361
+ line , cut = byteslice! ( current_line , @byte_pointer , byte_pointer_diff )
2362
+ elsif byte_pointer_diff < 0
2363
+ line , cut = byteslice! ( current_line , @byte_pointer + byte_pointer_diff , -byte_pointer_diff )
2364
+ end
2365
+ copy_for_vi ( cut )
2366
+ set_current_line ( line || '' , @byte_pointer + ( byte_pointer_diff < 0 ? byte_pointer_diff : 0 ) )
2367
+ end
2368
+
2369
+ private def vi_yank ( key , arg : nil )
2370
+ if @vi_waiting_operator
2371
+ copy_for_vi ( current_line ) if @vi_waiting_operator == :vi_yank_confirm && arg . nil?
2372
+ @vi_waiting_operator = nil
2373
+ @vi_waiting_operator_arg = nil
2374
+ else
2375
+ @vi_waiting_operator = :vi_yank_confirm
2376
+ @vi_waiting_operator_arg = arg || 1
2377
+ end
2378
+ end
2379
+
2380
+ private def vi_yank_confirm ( byte_pointer_diff )
2381
+ if byte_pointer_diff > 0
2382
+ cut = current_line . byteslice ( @byte_pointer , byte_pointer_diff )
2383
+ elsif byte_pointer_diff < 0
2384
+ cut = current_line . byteslice ( @byte_pointer + byte_pointer_diff , -byte_pointer_diff )
2385
+ end
2386
+ copy_for_vi ( cut )
2368
2387
end
2369
2388
2370
2389
private def vi_list_or_eof ( key )
0 commit comments