File tree Expand file tree Collapse file tree 2 files changed +39
-4
lines changed Expand file tree Collapse file tree 2 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -1291,10 +1291,32 @@ def insert_text(text)
1291
1291
1292
1292
def delete_text ( start = nil , length = nil )
1293
1293
if start . nil? and length . nil?
1294
- @line &.clear
1295
- @byte_pointer = 0
1296
- @cursor = 0
1297
- @cursor_max = 0
1294
+ if @is_multiline
1295
+ if @buffer_of_lines . size == 1
1296
+ @line &.clear
1297
+ @byte_pointer = 0
1298
+ @cursor = 0
1299
+ @cursor_max = 0
1300
+ elsif @line_index == ( @buffer_of_lines . size - 1 ) and @line_index > 0
1301
+ @buffer_of_lines . pop
1302
+ @line_index -= 1
1303
+ @line = @buffer_of_lines [ @line_index ]
1304
+ @byte_pointer = 0
1305
+ @cursor = 0
1306
+ @cursor_max = calculate_width ( @line )
1307
+ elsif @line_index < ( @buffer_of_lines . size - 1 )
1308
+ @buffer_of_lines . delete_at ( @line_index )
1309
+ @line = @buffer_of_lines [ @line_index ]
1310
+ @byte_pointer = 0
1311
+ @cursor = 0
1312
+ @cursor_max = calculate_width ( @line )
1313
+ end
1314
+ else
1315
+ @line &.clear
1316
+ @byte_pointer = 0
1317
+ @cursor = 0
1318
+ @cursor_max = 0
1319
+ end
1298
1320
elsif not start . nil? and not length . nil?
1299
1321
if @line
1300
1322
before = @line . byteslice ( 0 , start )
Original file line number Diff line number Diff line change @@ -59,4 +59,17 @@ def test_macro_commands_for_editing
59
59
@writer . write ( "abcde\C -b\C -b\C -b\C -x\C -d\C -x\C -h\C -x\C -v\C -a\C -f\C -f EF\C -x\C -t gh\C -x\M -t\C -b\C -b\C -b\C -b\C -b\C -b\C -b\C -b\C -x\M -u\C -x\M -l\C -x\M -c\n " )
60
60
assert_equal "a\C -aDE gh Fe" , Reline . readmultiline ( &proc { true } )
61
61
end
62
+
63
+ def test_delete_text_in_multiline
64
+ @writer . write ( "abc\n def\n xyz\n " )
65
+ result = Reline . readmultiline ( &proc { |str |
66
+ if str . include? ( 'xyz' )
67
+ Reline . delete_text
68
+ true
69
+ else
70
+ false
71
+ end
72
+ } )
73
+ assert_equal "abc\n def" , result
74
+ end
62
75
end
You can’t perform that action at this time.
0 commit comments