Allow inserting new lines
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good
All checks were successful
timw4mail/gilo/pipeline/head This commit looks good
This commit is contained in:
parent
3c6568f8f7
commit
19ab06ac4f
@ -87,6 +87,41 @@ func (d *Document) AppendRow(s string) {
|
|||||||
d.dirty = true
|
d.dirty = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Document) InsertRow(at int, s string) {
|
||||||
|
if at < 0 || at > d.RowCount() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var newRows []*Row
|
||||||
|
|
||||||
|
// Split the array of rows at the specified index
|
||||||
|
start := d.rows[0:at]
|
||||||
|
end := d.rows[at : d.RowCount()]
|
||||||
|
|
||||||
|
// Splice it back together
|
||||||
|
newRows = append(newRows, start...)
|
||||||
|
newRows = append(newRows, newRow(s))
|
||||||
|
newRows = append(newRows, end...)
|
||||||
|
|
||||||
|
d.rows = newRows
|
||||||
|
d.dirty = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Document) InsertNewline(at *gilo.Point) {
|
||||||
|
if at.X == 0 {
|
||||||
|
d.InsertRow(at.Y, "")
|
||||||
|
} else {
|
||||||
|
row := d.rows[at.Y]
|
||||||
|
|
||||||
|
// Insert the characters right of the cursor to the next line
|
||||||
|
d.InsertRow(at.Y + 1, string(row.chars[at.X:row.Size()]))
|
||||||
|
|
||||||
|
// Remove the characters copied to the next line
|
||||||
|
row.chars = row.chars[0:at.X]
|
||||||
|
row.update()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Document) MergeRows(to int, from int) {
|
func (d *Document) MergeRows(to int, from int) {
|
||||||
d.rows[to].appendString(d.rows[from].toString())
|
d.rows[to].appendString(d.rows[from].toString())
|
||||||
d.delRow(from)
|
d.delRow(from)
|
||||||
|
@ -45,6 +45,9 @@ func (e *editor) processKeypressChar(ch rune) bool {
|
|||||||
e.Save()
|
e.Save()
|
||||||
|
|
||||||
case key.Enter:
|
case key.Enter:
|
||||||
|
e.document.InsertNewline(e.cursor)
|
||||||
|
e.cursor.Y += 1
|
||||||
|
e.cursor.X = 0
|
||||||
|
|
||||||
case key.Backspace, key.Ctrl('h'):
|
case key.Backspace, key.Ctrl('h'):
|
||||||
e.delChar()
|
e.delChar()
|
||||||
|
Loading…
Reference in New Issue
Block a user