Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions cmd/micro/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func (c *Cursor) DeleteSelection() {
if c.curSelection[0] > c.curSelection[1] {
c.v.eh.Remove(c.curSelection[1], c.curSelection[0])
c.SetLoc(c.curSelection[1])
} else if c.GetSelection() == "" {
return
} else {
c.v.eh.Remove(c.curSelection[0], c.curSelection[1])
c.SetLoc(c.curSelection[0])
Expand Down
43 changes: 43 additions & 0 deletions cmd/micro/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ type View struct {
// This is useful for detecting double and triple clicks
lastClickTime time.Time

// lastCutTime stores when the last ctrl+k was issued.
// It is used for clearing the clipboard to replace it with fresh cut lines.
lastCutTime time.Time

// freshClip returns true if the clipboard has never been pasted.
freshClip bool

// Was the last mouse event actually a double click?
// Useful for detecting triple clicks -- if a double click is detected
// but the last mouse event was actually a double click, it's a triple click
Expand Down Expand Up @@ -210,6 +217,25 @@ func (v *View) Copy() {
} else {
messenger.Error("Clipboard is not supported on your system")
}
// Or there is no selection. Clear the clipboard.
} else {
clipboard.WriteAll("")
}
}

// AddCopy appends to the clipboard
func (v *View) AddCopy() {
if v.cursor.HasSelection() {
if !clipboard.Unsupported {
if clip, err := clipboard.ReadAll(); err != nil {
messenger.Error(err)
} else {
clipboard.WriteAll(clip + v.cursor.GetSelection())
}

} else {
messenger.Error("Clipboard is not supported on your system")
}
}
}

Expand Down Expand Up @@ -480,10 +506,13 @@ func (v *View) HandleEvent(event tcell.Event) {
v.eh.Redo()
case tcell.KeyCtrlC:
v.Copy()
v.freshClip = true
case tcell.KeyCtrlX:
v.Cut()
case tcell.KeyCtrlV:
v.freshClip = false
v.Paste()

case tcell.KeyCtrlA:
v.SelectAll()
case tcell.KeyCtrlO:
Expand All @@ -510,6 +539,20 @@ func (v *View) HandleEvent(event tcell.Event) {
case tcell.KeyCtrlD:
v.HalfPageDown()
relocate = false
case tcell.KeyCtrlK:
v.cursor.SelectLine()
if v.freshClip == true {
v.AddCopy()
} else if time.Since(v.lastCutTime)/time.Second > 10*time.Second || v.freshClip == false {
v.Copy()
} else {
return
}
v.freshClip = true
v.lastCutTime = time.Now()
v.cursor.DeleteSelection()
v.cursor.ResetSelection()
relocate = true
case tcell.KeyCtrlR:
if settings.Ruler == false {
settings.Ruler = true
Expand Down