turbo-editors/turbo-corepublic Fork 0
v1.0.3
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-core.git
git clone ssh://git@rickub.com/turbo-editors/turbo-core.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

paste.go · 53 lines · 1.6 KBGo Blame HistoryRaw
📦 Turbo Core — files rewritten outside reload into their windows; the agent window wraps what you type and keeps a long paste aside as a token (#28); configrepo fetches a shared .turbo-<slug> from a forge URL (#25) fe23288 k33g 5h ago1// A paste from the terminal: collected between its two marks and handed to
2// the window in front whole, or replayed as the keys it came as.
3
4package app
5
6import (
7 "strings"
8
9 "github.com/gdamore/tcell/v2"
10)
11
12// handlePaste marks the start and end of a bracketed paste from the terminal.
13//
14// tcell sends the pasted text as ordinary keys between the two marks, so
15// handleKey collects them while a paste is on, and the end mark decides
16// where the whole goes. An agent window in front gets it as one paste, which
17// is what lets a long one be kept aside as a token (acp.View.Paste). Any
18// other window gets the keys replayed exactly as it would have had them, so
19// nothing else changes: a paste into a file is typed, as it always was.
20func (a *App) handlePaste(ev *tcell.EventPaste) {
21 if ev.Start() {
22 a.pasting, a.pasted = true, nil
23 return
24 }
25 keys := a.pasted
26 a.pasting, a.pasted = false, nil
27
28 if agent := a.activeAgent(); agent != nil && len(a.modals) == 0 {
29 agent.view.Paste(pastedText(keys))
30 return
31 }
32 for _, key := range keys {
33 a.handleKey(key)
34 }
35}
36
37// pastedText puts the keys of a bracketed paste back into the text they
38// were: a rune for each character, a newline for each Enter, a tab for each
39// Tab. Anything else a terminal might send inside a paste is not text.
40func pastedText(keys []*tcell.EventKey) string {
41 var text strings.Builder
42 for _, key := range keys {
43 switch key.Key() {
44 case tcell.KeyRune:
45 text.WriteRune(key.Rune())
46 case tcell.KeyEnter, tcell.KeyLF:
47 text.WriteByte('\n')
48 case tcell.KeyTab:
49 text.WriteByte('\t')
50 }
51 }
52 return text.String()
53}