]> git.lizzy.rs Git - micro.git/commitdiff
DuplicateLine now duplicates the current selection if there is text selected
authorJon Craton <jncraton@gmail.com>
Sat, 15 Oct 2016 02:22:48 +0000 (22:22 -0400)
committerJon Craton <jncraton@gmail.com>
Sat, 15 Oct 2016 02:22:48 +0000 (22:22 -0400)
cmd/micro/actions.go

index a316293b60e384ecb1813822f4c29fc8590c70f5..0def2e3985a9520fd19e3f4937af088b3b116839 100644 (file)
@@ -922,15 +922,20 @@ func (v *View) Cut(usePlugin bool) bool {
        return false
 }
 
-// DuplicateLine duplicates the current line
+// DuplicateLine duplicates the current line or selection
 func (v *View) DuplicateLine(usePlugin bool) bool {
        if usePlugin && !PreActionCall("DuplicateLine", v) {
                return false
        }
 
-       v.Cursor.End()
-       v.Buf.Insert(v.Cursor.Loc, "\n"+v.Buf.Line(v.Cursor.Y))
-       v.Cursor.Right()
+       if v.Cursor.HasSelection() {
+               v.Buf.Insert(v.Cursor.CurSelection[1], v.Cursor.GetSelection())
+       } else {
+               v.Cursor.End()
+               v.Buf.Insert(v.Cursor.Loc, "\n"+v.Buf.Line(v.Cursor.Y))
+               v.Cursor.Right()
+       }
+
        messenger.Message("Duplicated line")
 
        if usePlugin {