reline 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47d262bd9b8ab9b3fb314863af068783c217d53177f947372eb979df2ceaf3cf
4
- data.tar.gz: 8112b4441c7946a697adf3d16ec79531fc744fac132ea3cca89ef16b9b6518d3
3
+ metadata.gz: 68e79c30bbef8d97090f7126f96c5ee0c32fa95e6dc120a91240a6e9ff3864c6
4
+ data.tar.gz: 857716d3f9ab324efef98d3cb42acf2bba17848012a832c5631ca3e6d2f15733
5
5
  SHA512:
6
- metadata.gz: 22570f23bfa74602ef627bf977982304b0e5849cbc52abb33f321a32b3860348eabb3efd88bfcfa6b46032433a012813a0fa9aa70422438d0f0694a724ca3055
7
- data.tar.gz: 6a30e3c69c1a64149a5cd0517e3c46c6dfb9d724532ded4ab4475c6b595bcf5cdf6b6ffd1b9d32156b8a8a447885bb918d35f78be90934a2e2513f87fdf40bb0
6
+ metadata.gz: b25e6a151ded60963f660ccafceef8c221577b9f2328b9daa10dc381f5ea63c293a9759a786ab02610eb2fb07c52f3a200303fd9ac672210658884cb9a57c88c
7
+ data.tar.gz: 8433437480cf5acf7d87aefc632cc641e9325f163ab1d00d1df9cea5d5f3977f05250b20b366d7fd21ae275edd8f152ddc5879fa88340fbf35990e9b2a7e9725
@@ -49,13 +49,13 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
49
49
  # 23 ^W
50
50
  :em_kill_region,
51
51
  # 24 ^X
52
- :ed_sequence_lead_in,
52
+ :ed_unassigned,
53
53
  # 25 ^Y
54
54
  :em_yank,
55
55
  # 26 ^Z
56
56
  :ed_ignore,
57
57
  # 27 ^[
58
- :em_meta_next,
58
+ :ed_unassigned,
59
59
  # 28 ^\
60
60
  :ed_ignore,
61
61
  # 29 ^]
@@ -319,9 +319,9 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
319
319
  # 158 M-^^
320
320
  :ed_unassigned,
321
321
  # 159 M-^_
322
- :em_copy_prev_word,
323
- # 160 M-SPACE
324
322
  :ed_unassigned,
323
+ # 160 M-SPACE
324
+ :em_set_mark,
325
325
  # 161 M-!
326
326
  :ed_unassigned,
327
327
  # 162 M-"
@@ -415,7 +415,7 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
415
415
  # 206 M-N
416
416
  :vi_search_next,
417
417
  # 207 M-O
418
- :ed_sequence_lead_in,
418
+ :ed_unassigned,
419
419
  # 208 M-P
420
420
  :vi_search_prev,
421
421
  # 209 M-Q
@@ -431,15 +431,15 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
431
431
  # 214 M-V
432
432
  :ed_unassigned,
433
433
  # 215 M-W
434
- :em_copy_region,
434
+ :ed_unassigned,
435
435
  # 216 M-X
436
- :ed_command,
437
- # 217 M-Y
438
436
  :ed_unassigned,
437
+ # 217 M-Y
438
+ :em_yank_pop,
439
439
  # 218 M-Z
440
440
  :ed_unassigned,
441
441
  # 219 M-[
442
- :ed_sequence_lead_in,
442
+ :ed_unassigned,
443
443
  # 220 M-\
444
444
  :ed_unassigned,
445
445
  # 221 M-]
@@ -495,9 +495,9 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
495
495
  # 246 M-v
496
496
  :ed_unassigned,
497
497
  # 247 M-w
498
- :em_copy_region,
498
+ :ed_unassigned,
499
499
  # 248 M-x
500
- :ed_command,
500
+ :ed_unassigned,
501
501
  # 249 M-y
502
502
  :ed_unassigned,
503
503
  # 250 M-z
@@ -17,7 +17,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
17
17
  # 7 ^G
18
18
  :ed_unassigned,
19
19
  # 8 ^H
20
- :ed_unassigned,
20
+ :ed_prev_char,
21
21
  # 9 ^I
22
22
  :ed_unassigned,
23
23
  # 10 ^J
@@ -41,7 +41,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
41
41
  # 19 ^S
42
42
  :ed_ignore,
43
43
  # 20 ^T
44
- :ed_unassigned,
44
+ :ed_transpose_chars,
45
45
  # 21 ^U
46
46
  :vi_kill_line_prev,
47
47
  # 22 ^V
@@ -51,7 +51,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
51
51
  # 24 ^X
52
52
  :ed_unassigned,
53
53
  # 25 ^Y
54
- :ed_unassigned,
54
+ :em_yank,
55
55
  # 26 ^Z
56
56
  :ed_unassigned,
57
57
  # 27 ^[
@@ -75,7 +75,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
75
75
  # 36 $
76
76
  :ed_move_to_end,
77
77
  # 37 %
78
- :vi_match,
78
+ :ed_unassigned,
79
79
  # 38 &
80
80
  :ed_unassigned,
81
81
  # 39 '
@@ -89,11 +89,11 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
89
89
  # 43 +
90
90
  :ed_next_history,
91
91
  # 44 ,
92
- :vi_repeat_prev_char,
92
+ :ed_unassigned,
93
93
  # 45 -
94
94
  :ed_prev_history,
95
95
  # 46 .
96
- :vi_redo,
96
+ :ed_unassigned,
97
97
  # 47 /
98
98
  :vi_search_prev,
99
99
  # 48 0
@@ -117,9 +117,9 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
117
117
  # 57 9
118
118
  :ed_argument_digit,
119
119
  # 58 :
120
- :ed_command,
120
+ :ed_unassigned,
121
121
  # 59 ;
122
- :vi_repeat_next_char,
122
+ :ed_unassigned,
123
123
  # 60 <
124
124
  :ed_unassigned,
125
125
  # 61 =
@@ -157,21 +157,21 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
157
157
  # 77 M
158
158
  :ed_unassigned,
159
159
  # 78 N
160
- :vi_repeat_search_prev,
160
+ :ed_unassigned,
161
161
  # 79 O
162
- :ed_sequence_lead_in,
162
+ :ed_unassigned,
163
163
  # 80 P
164
164
  :vi_paste_prev,
165
165
  # 81 Q
166
166
  :ed_unassigned,
167
167
  # 82 R
168
- :vi_replace_mode,
168
+ :ed_unassigned,
169
169
  # 83 S
170
- :vi_substitute_line,
170
+ :ed_unassigned,
171
171
  # 84 T
172
172
  :vi_to_prev_char,
173
173
  # 85 U
174
- :vi_undo_line,
174
+ :ed_unassigned,
175
175
  # 86 V
176
176
  :ed_unassigned,
177
177
  # 87 W
@@ -179,11 +179,11 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
179
179
  # 88 X
180
180
  :ed_delete_prev_char,
181
181
  # 89 Y
182
- :vi_yank_end,
182
+ :ed_unassigned,
183
183
  # 90 Z
184
184
  :ed_unassigned,
185
185
  # 91 [
186
- :ed_sequence_lead_in,
186
+ :ed_unassigned,
187
187
  # 92 \
188
188
  :ed_unassigned,
189
189
  # 93 ]
@@ -191,7 +191,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
191
191
  # 94 ^
192
192
  :vi_first_print,
193
193
  # 95 _
194
- :vi_history_word,
194
+ :ed_unassigned,
195
195
  # 96 `
196
196
  :ed_unassigned,
197
197
  # 97 a
@@ -221,7 +221,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
221
221
  # 109 m
222
222
  :ed_unassigned,
223
223
  # 110 n
224
- :vi_repeat_search_next,
224
+ :ed_unassigned,
225
225
  # 111 o
226
226
  :ed_unassigned,
227
227
  # 112 p
@@ -231,11 +231,11 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
231
231
  # 114 r
232
232
  :vi_replace_char,
233
233
  # 115 s
234
- :vi_substitute_char,
234
+ :ed_unassigned,
235
235
  # 116 t
236
236
  :vi_to_next_char,
237
237
  # 117 u
238
- :vi_undo,
238
+ :ed_unassigned,
239
239
  # 118 v
240
240
  :vi_histedit,
241
241
  # 119 w
@@ -253,9 +253,9 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
253
253
  # 125 }
254
254
  :ed_unassigned,
255
255
  # 126 ~
256
- :vi_change_case,
257
- # 127 ^?
258
256
  :ed_unassigned,
257
+ # 127 ^?
258
+ :em_delete_prev_char,
259
259
  # 128 M-^@
260
260
  :ed_unassigned,
261
261
  # 129 M-^A
@@ -415,7 +415,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
415
415
  # 206 M-N
416
416
  :ed_unassigned,
417
417
  # 207 M-O
418
- :ed_sequence_lead_in,
418
+ :ed_unassigned,
419
419
  # 208 M-P
420
420
  :ed_unassigned,
421
421
  # 209 M-Q
@@ -439,7 +439,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base
439
439
  # 218 M-Z
440
440
  :ed_unassigned,
441
441
  # 219 M-[
442
- :ed_sequence_lead_in,
442
+ :ed_unassigned,
443
443
  # 220 M-\
444
444
  :ed_unassigned,
445
445
  # 221 M-]
@@ -41,7 +41,7 @@ class Reline::KeyActor::ViInsert < Reline::KeyActor::Base
41
41
  # 19 ^S
42
42
  :vi_search_next,
43
43
  # 20 ^T
44
- :ed_insert,
44
+ :ed_transpose_chars,
45
45
  # 21 ^U
46
46
  :vi_kill_line_prev,
47
47
  # 22 ^V
@@ -51,7 +51,7 @@ class Reline::KeyActor::ViInsert < Reline::KeyActor::Base
51
51
  # 24 ^X
52
52
  :ed_insert,
53
53
  # 25 ^Y
54
- :ed_insert,
54
+ :em_yank,
55
55
  # 26 ^Z
56
56
  :ed_insert,
57
57
  # 27 ^[
@@ -33,8 +33,6 @@ class Reline::LineEditor
33
33
  vi_next_big_word
34
34
  vi_prev_big_word
35
35
  vi_end_big_word
36
- vi_repeat_next_char
37
- vi_repeat_prev_char
38
36
  }
39
37
 
40
38
  module CompletionState
@@ -229,10 +227,11 @@ class Reline::LineEditor
229
227
  @vi_clipboard = ''
230
228
  @vi_arg = nil
231
229
  @waiting_proc = nil
232
- @waiting_operator_proc = nil
233
- @waiting_operator_vi_arg = nil
230
+ @vi_waiting_operator = nil
231
+ @vi_waiting_operator_arg = nil
234
232
  @completion_journey_state = nil
235
233
  @completion_state = CompletionState::NORMAL
234
+ @completion_occurs = false
236
235
  @perfect_matched = nil
237
236
  @menu_info = nil
238
237
  @searching_prompt = nil
@@ -541,10 +540,6 @@ class Reline::LineEditor
541
540
  new_lines.size - y
542
541
  end
543
542
 
544
- def current_row
545
- wrapped_lines.flatten[wrapped_cursor_y]
546
- end
547
-
548
543
  def upper_space_height(wrapped_cursor_y)
549
544
  wrapped_cursor_y - screen_scroll_top
550
545
  end
@@ -935,37 +930,23 @@ class Reline::LineEditor
935
930
  end
936
931
 
937
932
  private def run_for_operators(key, method_symbol, &block)
938
- if @waiting_operator_proc
933
+ if @vi_waiting_operator
939
934
  if VI_MOTIONS.include?(method_symbol)
940
935
  old_byte_pointer = @byte_pointer
941
- @vi_arg = @waiting_operator_vi_arg if @waiting_operator_vi_arg&.> 1
936
+ @vi_arg = (@vi_arg || 1) * @vi_waiting_operator_arg
942
937
  block.(true)
943
938
  unless @waiting_proc
944
939
  byte_pointer_diff = @byte_pointer - old_byte_pointer
945
940
  @byte_pointer = old_byte_pointer
946
- @waiting_operator_proc.(byte_pointer_diff)
947
- else
948
- old_waiting_proc = @waiting_proc
949
- old_waiting_operator_proc = @waiting_operator_proc
950
- current_waiting_operator_proc = @waiting_operator_proc
951
- @waiting_proc = proc { |k|
952
- old_byte_pointer = @byte_pointer
953
- old_waiting_proc.(k)
954
- byte_pointer_diff = @byte_pointer - old_byte_pointer
955
- @byte_pointer = old_byte_pointer
956
- current_waiting_operator_proc.(byte_pointer_diff)
957
- @waiting_operator_proc = old_waiting_operator_proc
958
- }
941
+ send(@vi_waiting_operator, byte_pointer_diff)
942
+ cleanup_waiting
959
943
  end
960
944
  else
961
945
  # Ignores operator when not motion is given.
962
946
  block.(false)
947
+ cleanup_waiting
963
948
  end
964
- @waiting_operator_proc = nil
965
- @waiting_operator_vi_arg = nil
966
- if @vi_arg
967
- @vi_arg = nil
968
- end
949
+ @vi_arg = nil
969
950
  else
970
951
  block.(false)
971
952
  end
@@ -982,7 +963,7 @@ class Reline::LineEditor
982
963
  end
983
964
 
984
965
  def wrap_method_call(method_symbol, method_obj, key, with_operator = false)
985
- if @config.editing_mode_is?(:emacs, :vi_insert) and @waiting_proc.nil? and @waiting_operator_proc.nil?
966
+ if @config.editing_mode_is?(:emacs, :vi_insert) and @vi_waiting_operator.nil?
986
967
  not_insertion = method_symbol != :ed_insert
987
968
  process_insert(force: not_insertion)
988
969
  end
@@ -1001,11 +982,32 @@ class Reline::LineEditor
1001
982
  end
1002
983
  end
1003
984
 
985
+ private def cleanup_waiting
986
+ @waiting_proc = nil
987
+ @vi_waiting_operator = nil
988
+ @vi_waiting_operator_arg = nil
989
+ @searching_prompt = nil
990
+ @drop_terminate_spaces = false
991
+ end
992
+
1004
993
  private def process_key(key, method_symbol)
994
+ if key.is_a?(Symbol)
995
+ cleanup_waiting
996
+ elsif @waiting_proc
997
+ old_byte_pointer = @byte_pointer
998
+ @waiting_proc.call(key)
999
+ if @vi_waiting_operator
1000
+ byte_pointer_diff = @byte_pointer - old_byte_pointer
1001
+ @byte_pointer = old_byte_pointer
1002
+ send(@vi_waiting_operator, byte_pointer_diff)
1003
+ cleanup_waiting
1004
+ end
1005
+ @kill_ring.process
1006
+ return
1007
+ end
1008
+
1005
1009
  if method_symbol and respond_to?(method_symbol, true)
1006
1010
  method_obj = method(method_symbol)
1007
- else
1008
- method_obj = nil
1009
1011
  end
1010
1012
  if method_symbol and key.is_a?(Symbol)
1011
1013
  if @vi_arg and argumentable?(method_obj)
@@ -1027,8 +1029,6 @@ class Reline::LineEditor
1027
1029
  run_for_operators(key, method_symbol) do |with_operator|
1028
1030
  wrap_method_call(method_symbol, method_obj, key, with_operator)
1029
1031
  end
1030
- elsif @waiting_proc
1031
- @waiting_proc.(key)
1032
1032
  elsif method_obj
1033
1033
  wrap_method_call(method_symbol, method_obj, key)
1034
1034
  else
@@ -1039,9 +1039,6 @@ class Reline::LineEditor
1039
1039
  @vi_arg = nil
1040
1040
  end
1041
1041
  end
1042
- elsif @waiting_proc
1043
- @waiting_proc.(key)
1044
- @kill_ring.process
1045
1042
  elsif method_obj
1046
1043
  if method_symbol == :ed_argument_digit
1047
1044
  wrap_method_call(method_symbol, method_obj, key)
@@ -1118,42 +1115,35 @@ class Reline::LineEditor
1118
1115
  end
1119
1116
  old_lines = @buffer_of_lines.dup
1120
1117
  @first_char = false
1121
- completion_occurs = false
1118
+ @completion_occurs = false
1122
1119
  if @config.editing_mode_is?(:emacs, :vi_insert) and key.char == "\C-i".ord
1123
1120
  if !@config.disable_completion
1124
1121
  process_insert(force: true)
1125
1122
  if @config.autocompletion
1126
1123
  @completion_state = CompletionState::NORMAL
1127
- completion_occurs = move_completed_list(:down)
1124
+ @completion_occurs = move_completed_list(:down)
1128
1125
  else
1129
1126
  @completion_journey_state = nil
1130
1127
  result = call_completion_proc
1131
1128
  if result.is_a?(Array)
1132
- completion_occurs = true
1129
+ @completion_occurs = true
1133
1130
  complete(result, false)
1134
1131
  end
1135
1132
  end
1136
1133
  end
1137
- elsif @config.editing_mode_is?(:emacs, :vi_insert) and key.char == :completion_journey_up
1138
- if not @config.disable_completion and @config.autocompletion
1139
- process_insert(force: true)
1140
- @completion_state = CompletionState::NORMAL
1141
- completion_occurs = move_completed_list(:up)
1142
- end
1143
1134
  elsif @config.editing_mode_is?(:vi_insert) and ["\C-p".ord, "\C-n".ord].include?(key.char)
1144
1135
  # In vi mode, move completed list even if autocompletion is off
1145
1136
  if not @config.disable_completion
1146
1137
  process_insert(force: true)
1147
1138
  @completion_state = CompletionState::NORMAL
1148
- completion_occurs = move_completed_list("\C-p".ord == key.char ? :up : :down)
1139
+ @completion_occurs = move_completed_list("\C-p".ord == key.char ? :up : :down)
1149
1140
  end
1150
1141
  elsif Symbol === key.char and respond_to?(key.char, true)
1151
1142
  process_key(key.char, key.char)
1152
1143
  else
1153
1144
  normal_char(key)
1154
1145
  end
1155
-
1156
- unless completion_occurs
1146
+ unless @completion_occurs
1157
1147
  @completion_state = CompletionState::NORMAL
1158
1148
  @completion_journey_state = nil
1159
1149
  end
@@ -1164,7 +1154,7 @@ class Reline::LineEditor
1164
1154
  end
1165
1155
 
1166
1156
  modified = old_lines != @buffer_of_lines
1167
- if !completion_occurs && modified && !@config.disable_completion && @config.autocompletion
1157
+ if !@completion_occurs && modified && !@config.disable_completion && @config.autocompletion
1168
1158
  # Auto complete starts only when edited
1169
1159
  process_insert(force: true)
1170
1160
  @completion_journey_state = retrieve_completion_journey_state
@@ -1433,6 +1423,14 @@ class Reline::LineEditor
1433
1423
  end
1434
1424
  end
1435
1425
 
1426
+ private def completion_journey_up(key)
1427
+ if not @config.disable_completion and @config.autocompletion
1428
+ @completion_state = CompletionState::NORMAL
1429
+ @completion_occurs = move_completed_list(:up)
1430
+ end
1431
+ end
1432
+ alias_method :menu_complete_backward, :completion_journey_up
1433
+
1436
1434
  # Editline:: +ed-unassigned+ This editor command always results in an error.
1437
1435
  # GNU Readline:: There is no corresponding macro.
1438
1436
  private def ed_unassigned(key) end # do nothing
@@ -1534,6 +1532,7 @@ class Reline::LineEditor
1534
1532
  @byte_pointer = 0
1535
1533
  end
1536
1534
  alias_method :beginning_of_line, :ed_move_to_beg
1535
+ alias_method :vi_zero, :ed_move_to_beg
1537
1536
 
1538
1537
  private def ed_move_to_end(key)
1539
1538
  @byte_pointer = 0
@@ -2319,50 +2318,63 @@ class Reline::LineEditor
2319
2318
  copy_for_vi(deleted)
2320
2319
  end
2321
2320
 
2322
- private def vi_zero(key)
2323
- @byte_pointer = 0
2321
+ private def vi_change_meta(key, arg: nil)
2322
+ if @vi_waiting_operator
2323
+ set_current_line('', 0) if @vi_waiting_operator == :vi_change_meta_confirm && arg.nil?
2324
+ @vi_waiting_operator = nil
2325
+ @vi_waiting_operator_arg = nil
2326
+ else
2327
+ @drop_terminate_spaces = true
2328
+ @vi_waiting_operator = :vi_change_meta_confirm
2329
+ @vi_waiting_operator_arg = arg || 1
2330
+ end
2324
2331
  end
2325
2332
 
2326
- private def vi_change_meta(key, arg: 1)
2327
- @drop_terminate_spaces = true
2328
- @waiting_operator_proc = proc { |byte_pointer_diff|
2329
- if byte_pointer_diff > 0
2330
- line, cut = byteslice!(current_line, @byte_pointer, byte_pointer_diff)
2331
- elsif byte_pointer_diff < 0
2332
- line, cut = byteslice!(current_line, @byte_pointer + byte_pointer_diff, -byte_pointer_diff)
2333
- end
2334
- set_current_line(line)
2335
- copy_for_vi(cut)
2336
- @byte_pointer += byte_pointer_diff if byte_pointer_diff < 0
2337
- @config.editing_mode = :vi_insert
2338
- @drop_terminate_spaces = false
2339
- }
2340
- @waiting_operator_vi_arg = arg
2333
+ private def vi_change_meta_confirm(byte_pointer_diff)
2334
+ vi_delete_meta_confirm(byte_pointer_diff)
2335
+ @config.editing_mode = :vi_insert
2336
+ @drop_terminate_spaces = false
2341
2337
  end
2342
2338
 
2343
- private def vi_delete_meta(key, arg: 1)
2344
- @waiting_operator_proc = proc { |byte_pointer_diff|
2345
- if byte_pointer_diff > 0
2346
- line, cut = byteslice!(current_line, @byte_pointer, byte_pointer_diff)
2347
- elsif byte_pointer_diff < 0
2348
- line, cut = byteslice!(current_line, @byte_pointer + byte_pointer_diff, -byte_pointer_diff)
2349
- end
2350
- copy_for_vi(cut)
2351
- set_current_line(line || '', @byte_pointer + (byte_pointer_diff < 0 ? byte_pointer_diff : 0))
2352
- }
2353
- @waiting_operator_vi_arg = arg
2339
+ private def vi_delete_meta(key, arg: nil)
2340
+ if @vi_waiting_operator
2341
+ set_current_line('', 0) if @vi_waiting_operator == :vi_delete_meta_confirm && arg.nil?
2342
+ @vi_waiting_operator = nil
2343
+ @vi_waiting_operator_arg = nil
2344
+ else
2345
+ @vi_waiting_operator = :vi_delete_meta_confirm
2346
+ @vi_waiting_operator_arg = arg || 1
2347
+ end
2354
2348
  end
2355
2349
 
2356
- private def vi_yank(key, arg: 1)
2357
- @waiting_operator_proc = proc { |byte_pointer_diff|
2358
- if byte_pointer_diff > 0
2359
- cut = current_line.byteslice(@byte_pointer, byte_pointer_diff)
2360
- elsif byte_pointer_diff < 0
2361
- cut = current_line.byteslice(@byte_pointer + byte_pointer_diff, -byte_pointer_diff)
2362
- end
2363
- copy_for_vi(cut)
2364
- }
2365
- @waiting_operator_vi_arg = arg
2350
+ private def vi_delete_meta_confirm(byte_pointer_diff)
2351
+ if byte_pointer_diff > 0
2352
+ line, cut = byteslice!(current_line, @byte_pointer, byte_pointer_diff)
2353
+ elsif byte_pointer_diff < 0
2354
+ line, cut = byteslice!(current_line, @byte_pointer + byte_pointer_diff, -byte_pointer_diff)
2355
+ end
2356
+ copy_for_vi(cut)
2357
+ set_current_line(line || '', @byte_pointer + (byte_pointer_diff < 0 ? byte_pointer_diff : 0))
2358
+ end
2359
+
2360
+ private def vi_yank(key, arg: nil)
2361
+ if @vi_waiting_operator
2362
+ copy_for_vi(current_line) if @vi_waiting_operator == :vi_yank_confirm && arg.nil?
2363
+ @vi_waiting_operator = nil
2364
+ @vi_waiting_operator_arg = nil
2365
+ else
2366
+ @vi_waiting_operator = :vi_yank_confirm
2367
+ @vi_waiting_operator_arg = arg || 1
2368
+ end
2369
+ end
2370
+
2371
+ private def vi_yank_confirm(byte_pointer_diff)
2372
+ if byte_pointer_diff > 0
2373
+ cut = current_line.byteslice(@byte_pointer, byte_pointer_diff)
2374
+ elsif byte_pointer_diff < 0
2375
+ cut = current_line.byteslice(@byte_pointer + byte_pointer_diff, -byte_pointer_diff)
2376
+ end
2377
+ copy_for_vi(cut)
2366
2378
  end
2367
2379
 
2368
2380
  private def vi_list_or_eof(key)
@@ -2467,18 +2479,11 @@ class Reline::LineEditor
2467
2479
  end
2468
2480
 
2469
2481
  private def vi_to_column(key, arg: 0)
2470
- current_row_width = calculate_width(current_row)
2471
- @byte_pointer, = current_line.grapheme_clusters.inject([0, 0]) { |total, gc|
2472
- # total has [byte_size, cursor]
2482
+ # Implementing behavior of vi, not Readline's vi-mode.
2483
+ @byte_pointer, = current_line.grapheme_clusters.inject([0, 0]) { |(total_byte_size, total_width), gc|
2473
2484
  mbchar_width = Reline::Unicode.get_mbchar_width(gc)
2474
- if (total.last + mbchar_width) >= arg
2475
- break total
2476
- elsif (total.last + mbchar_width) >= current_row_width
2477
- break total
2478
- else
2479
- total = [total.first + gc.bytesize, total.last + mbchar_width]
2480
- total
2481
- end
2485
+ break [total_byte_size, total_width] if (total_width + mbchar_width) >= arg
2486
+ [total_byte_size + gc.bytesize, total_width + mbchar_width]
2482
2487
  }
2483
2488
  end
2484
2489
 
@@ -2626,6 +2631,11 @@ class Reline::LineEditor
2626
2631
  end
2627
2632
  alias_method :exchange_point_and_mark, :em_exchange_mark
2628
2633
 
2629
- private def em_meta_next(key)
2634
+ private def emacs_editing_mode(key)
2635
+ @config.editing_mode = :emacs
2636
+ end
2637
+
2638
+ private def vi_editing_mode(key)
2639
+ @config.editing_mode = :vi_insert
2630
2640
  end
2631
2641
  end
@@ -1,3 +1,3 @@
1
1
  module Reline
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-09 00:00:00.000000000 Z
11
+ date: 2024-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: io-console