@@ -911,28 +911,36 @@ def dialog_proc_scope_completion_journey_data
911
911
)
912
912
end
913
913
914
- private def run_for_operators ( key , method_symbol , &block )
914
+ private def run_for_operators ( key , method_symbol )
915
+ # Reject multibyte input (converted to ed_insert) in vi_command mode
916
+ return if method_symbol == :ed_insert && @config . editing_mode_is? ( :vi_command ) && !@waiting_proc
917
+
918
+ if ARGUMENT_DIGIT_METHODS . include? ( method_symbol ) && !@waiting_proc
919
+ wrap_method_call ( method_symbol , key , false )
920
+ return
921
+ end
922
+
915
923
if @vi_waiting_operator
916
- if VI_MOTIONS . include? ( method_symbol )
924
+ if @waiting_proc || VI_MOTIONS . include? ( method_symbol )
917
925
old_byte_pointer = @byte_pointer
918
926
@vi_arg = ( @vi_arg || 1 ) * @vi_waiting_operator_arg
919
- block . ( true )
927
+ wrap_method_call ( method_symbol , key , true )
920
928
unless @waiting_proc
921
929
byte_pointer_diff = @byte_pointer - old_byte_pointer
922
930
@byte_pointer = old_byte_pointer
923
- method_obj = method ( @vi_waiting_operator )
924
- wrap_method_call ( @vi_waiting_operator , method_obj , byte_pointer_diff )
931
+ __send__ ( @vi_waiting_operator , byte_pointer_diff )
925
932
cleanup_waiting
926
933
end
927
934
else
928
935
# Ignores operator when not motion is given.
929
- block . ( false )
936
+ wrap_method_call ( method_symbol , key , false )
930
937
cleanup_waiting
931
938
end
932
- @vi_arg = nil
933
939
else
934
- block . ( false )
940
+ wrap_method_call ( method_symbol , key , false )
935
941
end
942
+ @vi_arg = nil
943
+ @kill_ring . process
936
944
end
937
945
938
946
private def argumentable? ( method_obj )
@@ -945,20 +953,23 @@ def dialog_proc_scope_completion_journey_data
945
953
method_obj and method_obj . parameters . any? { |param | param [ 0 ] == :key and param [ 1 ] == :inclusive }
946
954
end
947
955
948
- def wrap_method_call ( method_symbol , method_obj , key , with_operator = false )
949
- if @config . editing_mode_is? ( :emacs , :vi_insert ) and @vi_waiting_operator . nil?
950
- not_insertion = method_symbol != :ed_insert
951
- process_insert ( force : not_insertion )
956
+ def wrap_method_call ( method_symbol , key , with_operator )
957
+ if @waiting_proc
958
+ @waiting_proc . call ( key )
959
+ return
952
960
end
961
+
962
+ return unless respond_to? ( method_symbol , true )
963
+ method_obj = method ( method_symbol )
953
964
if @vi_arg and argumentable? ( method_obj )
954
- if with_operator and inclusive? ( method_obj )
955
- method_obj . ( key , arg : @vi_arg , inclusive : true )
965
+ if inclusive? ( method_obj )
966
+ method_obj . ( key , arg : @vi_arg , inclusive : with_operator )
956
967
else
957
968
method_obj . ( key , arg : @vi_arg )
958
969
end
959
970
else
960
- if with_operator and inclusive? ( method_obj )
961
- method_obj . ( key , inclusive : true )
971
+ if inclusive? ( method_obj )
972
+ method_obj . ( key , inclusive : with_operator )
962
973
else
963
974
method_obj . ( key )
964
975
end
@@ -984,50 +995,9 @@ def wrap_method_call(method_symbol, method_obj, key, with_operator = false)
984
995
cleanup_waiting unless VI_WAITING_ACCEPT_METHODS . include? ( method_symbol ) || VI_MOTIONS . include? ( method_symbol )
985
996
end
986
997
987
- if @waiting_proc
988
- old_byte_pointer = @byte_pointer
989
- @waiting_proc . call ( key )
990
- if @vi_waiting_operator
991
- byte_pointer_diff = @byte_pointer - old_byte_pointer
992
- @byte_pointer = old_byte_pointer
993
- method_obj = method ( @vi_waiting_operator )
994
- wrap_method_call ( @vi_waiting_operator , method_obj , byte_pointer_diff )
995
- cleanup_waiting
996
- end
997
- @kill_ring . process
998
- return
999
- end
1000
-
1001
- # Reject multibyte input (converted to ed_insert) in vi_command mode
1002
- return if method_symbol == :ed_insert && @config . editing_mode_is? ( :vi_command )
998
+ process_insert ( force : method_symbol != :ed_insert )
1003
999
1004
- if method_symbol and respond_to? ( method_symbol , true )
1005
- method_obj = method ( method_symbol )
1006
- end
1007
- if @vi_arg
1008
- if ARGUMENT_DIGIT_METHODS . include? ( method_symbol )
1009
- ed_argument_digit ( key )
1010
- else
1011
- if argumentable? ( method_obj )
1012
- run_for_operators ( key , method_symbol ) do |with_operator |
1013
- wrap_method_call ( method_symbol , method_obj , key , with_operator )
1014
- end
1015
- elsif method_obj
1016
- wrap_method_call ( method_symbol , method_obj , key )
1017
- end
1018
- @kill_ring . process
1019
- @vi_arg = nil
1020
- end
1021
- elsif method_obj
1022
- if method_symbol == :ed_argument_digit
1023
- wrap_method_call ( method_symbol , method_obj , key )
1024
- else
1025
- run_for_operators ( key , method_symbol ) do |with_operator |
1026
- wrap_method_call ( method_symbol , method_obj , key , with_operator )
1027
- end
1028
- end
1029
- @kill_ring . process
1030
- end
1000
+ run_for_operators ( key , method_symbol )
1031
1001
end
1032
1002
1033
1003
def update ( key )
@@ -1049,11 +1019,8 @@ def input_key(key)
1049
1019
finish
1050
1020
return
1051
1021
end
1052
- @dialogs . each do |dialog |
1053
- if key . method_symbol == dialog . name
1054
- return
1055
- end
1056
- end
1022
+ return if @dialogs . any? { |dialog | dialog . name == key . method_symbol }
1023
+
1057
1024
@completion_occurs = false
1058
1025
1059
1026
process_key ( key . char , key . method_symbol )
@@ -1413,9 +1380,16 @@ def finish
1413
1380
1414
1381
insert_text ( str )
1415
1382
end
1416
- alias_method :ed_digit , :ed_insert
1417
1383
alias_method :self_insert , :ed_insert
1418
1384
1385
+ private def ed_digit ( key )
1386
+ if @vi_arg
1387
+ ed_argument_digit ( key )
1388
+ else
1389
+ ed_insert ( key )
1390
+ end
1391
+ end
1392
+
1419
1393
private def insert_raw_char ( str , arg : 1 )
1420
1394
arg . times do
1421
1395
if str == "\C -j" or str == "\C -m"
@@ -1461,7 +1435,14 @@ def finish
1461
1435
@byte_pointer = 0
1462
1436
end
1463
1437
alias_method :beginning_of_line , :ed_move_to_beg
1464
- alias_method :vi_zero , :ed_move_to_beg
1438
+
1439
+ private def vi_zero ( key )
1440
+ if @vi_arg
1441
+ ed_argument_digit ( key )
1442
+ else
1443
+ ed_move_to_beg ( key )
1444
+ end
1445
+ end
1465
1446
1466
1447
private def ed_move_to_end ( key )
1467
1448
@byte_pointer = current_line . bytesize
0 commit comments