File tree 1 file changed +27
-1
lines changed
1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -367,12 +367,38 @@ func (b *Buffer) Handle(r core.Rect, evt termbox.Event) bool {
367
367
}
368
368
b .SetPos (curPos )
369
369
case termbox .KeyEnter :
370
- ch = '\n'
370
+ b .Sel = - 1
371
+ pos := b .Pos ()- 1
372
+ tabs := 0
373
+ for pos >= 0 && b .GB .Get (pos ) != '\n' {
374
+ if b .GB .Get (pos ) == '\t' {
375
+ tabs ++
376
+ } else {
377
+ tabs = 0
378
+ }
379
+ pos --
380
+ }
381
+ b .Insert ('\n' )
382
+ for tabs > 0 {
383
+ b .Insert ('\t' )
384
+ tabs --
385
+ }
386
+ break
371
387
case termbox .KeySpace :
372
388
ch = ' '
373
389
case termbox .KeyTab :
374
390
ch = '\t'
375
391
case termbox .KeyBackspace , termbox .KeyBackspace2 :
392
+ if b .Sel != - 1 {
393
+ curPos := b .Pos ()
394
+ pos1 , pos2 := b .Sel , curPos
395
+ if pos1 > pos2 {
396
+ pos1 , pos2 = pos2 , pos1
397
+ }
398
+ b .GB .Cut (pos1 , pos2 - pos1 )
399
+ b .Sel = - 1
400
+ break
401
+ }
376
402
b .Sel = - 1
377
403
curPos := GetPos (b .GB , b .CurX , b .CurY )
378
404
if curPos <= 0 {
You can’t perform that action at this time.
0 commit comments