Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete line on Ctrl-Y key in editor #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func simpleEditor(v *View, key Key, ch rune, mod Modifier) {
v.EditDelete(true)
case key == KeyDelete:
v.EditDelete(false)
case key == KeyCtrlY:
v.EditDeleteLine()
case key == KeyInsert:
v.Overwrite = !v.Overwrite
case key == KeyEnter:
Expand All @@ -58,6 +60,20 @@ func (v *View) EditWrite(ch rune) {
v.MoveCursor(1, 0, true)
}

// EditDelete deletes a line at the cursor position.
func (v *View) EditDeleteLine() error {
v.tainted = true
_, y, err := v.realPosition(0, v.oy+v.cy)
if err != nil {
return err
}
if y < 0 || y >= len(v.lines) {
return errors.New("invalid point")
}
v.lines = append(v.lines[:y], v.lines[y+1:]...)
return nil
}

// EditDelete deletes a rune at the cursor position. back determines the
// direction.
func (v *View) EditDelete(back bool) {
Expand Down