Skip to content
Open
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/maaslalani/sheets
go 1.25.7

require (
github.com/atotto/clipboard v0.1.4
github.com/charmbracelet/bubbles v1.0.0
github.com/charmbracelet/bubbletea v1.3.10
github.com/charmbracelet/lipgloss v1.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/bubbles v1.0.0 h1:12J8/ak/uCZEMQ6KU7pcfwceyjLlWsDLAxB5fXonfvc=
Expand Down
19 changes: 18 additions & 1 deletion internal/sheets/clipboard.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package sheets

import tea "github.com/charmbracelet/bubbletea"
import (
"strings"
sysclip "github.com/atotto/clipboard"
tea "github.com/charmbracelet/bubbletea"
)

func cloneKeySequence(keys []tea.KeyMsg) []tea.KeyMsg {
return append([]tea.KeyMsg(nil), keys...)
Expand All @@ -18,6 +22,17 @@ func cloneClipboard(clip clipboard) clipboard {
return cloned
}

func (clip clipboard) String() string {
var build strings.Builder
for i, row := range clip.cells {
build.WriteString(strings.Join(row, "\t"))
if i < len(clip.cells)-1 {
build.WriteString("\n")
}
}
return build.String()
}

func (m *model) saveLastChange(keys []tea.KeyMsg) {
if m.replayingChange {
return
Expand Down Expand Up @@ -77,6 +92,7 @@ func (m *model) storeYankClipboard(clip clipboard) {
m.setRegisterClipboard(m.activeRegister, clip)
}
m.setUnnamedClipboard(clip)
_ = sysclip.WriteAll(clip.String())
}

func (m *model) storeDeleteClipboard(clip clipboard) {
Expand All @@ -88,6 +104,7 @@ func (m *model) storeDeleteClipboard(clip clipboard) {
}
m.shiftDeleteRegisters(clip)
m.setUnnamedClipboard(clip)
_ = sysclip.WriteAll(clip.String())
}

func (m model) clipboardForPaste() (clipboard, bool) {
Expand Down