+
+// MoveLinesUp moves the range of lines up one row
+func (b *Buffer) MoveLinesUp(start int, end int) {
+ // 0 < start < end <= len(b.lines)
+ if start < 1 || start >= end || end > len(b.lines) {
+ return // what to do? FIXME
+ }
+ if end == len(b.lines) {
+ b.Insert(
+ Loc{
+ utf8.RuneCount(b.lines[end-1]),
+ end - 1,
+ },
+ "\n"+b.Line(start-1),
+ )
+ } else {
+ b.Insert(
+ Loc{0, end},
+ b.Line(start-1)+"\n",
+ )
+ }
+ b.Remove(
+ Loc{0, start - 1},
+ Loc{0, start},
+ )
+}
+
+// MoveLinesDown moves the range of lines down one row
+func (b *Buffer) MoveLinesDown(start int, end int) {
+ // 0 <= start < end < len(b.lines)
+ // if end == len(b.lines), we can't do anything here because the
+ // last line is unaccessible, FIXME
+ if start < 0 || start >= end || end >= len(b.lines)-1 {
+ return // what to do? FIXME
+ }
+ b.Insert(
+ Loc{0, start},
+ b.Line(end)+"\n",
+ )
+ end++
+ b.Remove(
+ Loc{0, end},
+ Loc{0, end + 1},
+ )
+}