2014-01-23 06:44:42 +08:00
|
|
|
// Copyright 2014 The gocui Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2014-01-23 06:44:08 +08:00
|
|
|
package gocui
|
|
|
|
|
2014-01-23 07:00:07 +08:00
|
|
|
// editWrite writes a rune at the cursor position.
|
2014-01-23 06:44:08 +08:00
|
|
|
func (v *View) editWrite(ch rune) error {
|
|
|
|
v.writeRune(v.cx, v.cy, ch)
|
2014-01-24 04:26:53 +08:00
|
|
|
if err := v.SetCursor(v.cx+1, v.cy); err != nil {
|
2014-01-23 06:44:08 +08:00
|
|
|
if err := v.SetOrigin(v.ox+1, v.oy); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-01-23 07:00:07 +08:00
|
|
|
// editDelete deletes a rune at the cursor position. back determines
|
|
|
|
// the direction.
|
2014-01-23 06:44:08 +08:00
|
|
|
func (v *View) editDelete(back bool) error {
|
|
|
|
if back {
|
|
|
|
v.deleteRune(v.cx-1, v.cy)
|
2014-01-24 04:26:53 +08:00
|
|
|
if err := v.SetCursor(v.cx-1, v.cy); err != nil && v.ox > 0 {
|
|
|
|
if err := v.SetOrigin(v.ox-1, v.oy); err != nil {
|
2014-01-23 06:44:08 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
v.deleteRune(v.cx, v.cy)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-01-23 07:00:07 +08:00
|
|
|
// editLine inserts a new line under the cursor.
|
2014-01-23 06:44:08 +08:00
|
|
|
func (v *View) editLine() error {
|
|
|
|
v.addLine(v.cy + 1)
|
2014-01-24 04:26:53 +08:00
|
|
|
if err := v.SetCursor(v.cx, v.cy+1); err != nil {
|
|
|
|
if err := v.SetOrigin(v.ox, v.oy+1); err != nil {
|
2014-01-23 06:44:08 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2014-01-24 04:26:53 +08:00
|
|
|
if err := v.SetCursor(0, v.cy); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := v.SetOrigin(0, v.oy); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-01-23 06:44:08 +08:00
|
|
|
return nil
|
|
|
|
}
|