c.OrigSelection, c.CurSelection = b.OrigSelection, b.CurSelection
}
+// CopySelection copies the user's selection to either "primary" or "clipboard"
+func (c *Cursor) CopySelection(target string) {
+ if c.HasSelection() {
+ if target != "primary" || c.buf.Settings["useprimary"].(bool) {
+ clipboard.WriteAll(c.GetSelection(), target)
+ }
+ }
+}
+
// ResetSelection resets the user's selection
func (c *Cursor) ResetSelection() {
c.CurSelection[0] = c.buf.Start()
// SetSelectionStart sets the start of the selection
func (c *Cursor) SetSelectionStart(pos Loc) {
c.CurSelection[0] = pos
- // Copy to primary clipboard for linux
- if c.HasSelection() {
- clipboard.WriteAll(c.GetSelection(), "primary")
- }
}
// SetSelectionEnd sets the end of the selection
func (c *Cursor) SetSelectionEnd(pos Loc) {
c.CurSelection[1] = pos
- // Copy to primary clipboard for linux
- if c.HasSelection() {
- clipboard.WriteAll(c.GetSelection(), "primary")
- }
}
// HasSelection returns whether or not the user has selected anything
// GetSelection returns the cursor's selection
func (c *Cursor) GetSelection() string {
- if c.CurSelection[0].GreaterThan(c.CurSelection[1]) {
- return c.buf.Substr(c.CurSelection[1], c.CurSelection[0])
+ if InBounds(c.CurSelection[0], c.buf) && InBounds(c.CurSelection[1], c.buf) {
+ if c.CurSelection[0].GreaterThan(c.CurSelection[1]) {
+ return c.buf.Substr(c.CurSelection[1], c.CurSelection[0])
+ }
+ return c.buf.Substr(c.CurSelection[0], c.CurSelection[1])
}
- return c.buf.Substr(c.CurSelection[0], c.CurSelection[1])
+ return ""
}
// SelectLine selects the current line