github.com/grzegorz-zur/bm@v0.0.0-20240312214136-6fc133e3e2c0/change.go (about) 1 package main 2 3 // Insert inserts content to the file. 4 func (file *File) Insert(content string) { 5 file.content = file.content[:file.location] + content + file.content[file.location:] 6 file.location += len(content) 7 file.changed = true 8 file.Archive() 9 } 10 11 // Backspace deletes rune on the left. 12 func (file *File) Backspace() { 13 if file.AtFileStart() { 14 return 15 } 16 file.MoveLeft() 17 file.Delete() 18 } 19 20 // Delete removes current rune. 21 func (file *File) Delete() { 22 if file.AtFileEnd() { 23 return 24 } 25 _, size := file.current() 26 from := file.location 27 to := from + size 28 file.Remove(from, to) 29 } 30 31 // DeleteLine removes current line. 32 func (file *File) DeleteLine() { 33 location := file.location 34 file.MoveLineStart() 35 from := file.location 36 file.MoveLineEnd() 37 file.MoveRight() 38 to := file.location 39 file.location = location 40 file.Remove(from, to) 41 } 42 43 // Remove deletes content from the file. 44 func (file *File) Remove(from, to int) { 45 file.content = file.content[:from] + file.content[to:] 46 if file.location > from { 47 file.location = from 48 } 49 file.changed = true 50 file.Archive() 51 }