Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turn key events into paste events if there are enough in the buffer
Browse files Browse the repository at this point in the history
zyedidia authored and JoeKar committed Oct 15, 2024

Verified

This commit was signed with the committer’s verified signature.
rfratto Robert Fratto
1 parent db503d3 commit 9bdff1f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tscreen.go
Original file line number Diff line number Diff line change
@@ -1575,6 +1575,19 @@ func (t *tScreen) parseBracketedPaste(buf *bytes.Buffer, evs *[]Event) (bool, bo
return false, false
}

const pasteSz = 64

func (t *tScreen) parsePaste(buf *bytes.Buffer, evs *[]Event) (bool, bool) {
idx := bytes.Index(buf.Bytes(), []byte{'\x1b'})
if idx == -1 && buf.Len() >= pasteSz || idx >= pasteSz {
data, _ := buf.ReadBytes('\x1b')
text := strings.Replace(string(data), "\r", "\n", -1)
*evs = append(*evs, NewEventPaste(text))
return true, true
}
return false, false
}

func (t *tScreen) scanInput(buf *bytes.Buffer, expire bool) {
evs := t.collectEventsFromInput(buf, expire)

@@ -1618,6 +1631,12 @@ func (t *tScreen) collectEventsFromInput(buf *bytes.Buffer, expire bool) []Event
partials++
}

if part, comp := t.parsePaste(buf, &res); comp {
continue
} else if part {
partials++
}

if part, comp := t.parseRune(buf, &res); comp {
continue
} else if part {
@@ -1750,7 +1769,7 @@ func (t *tScreen) inputLoop(stopQ chan struct{}) {
return
default:
}
chunk := make([]byte, 128)
chunk := make([]byte, 2048)
n, e := t.tty.Read(chunk)
switch e {
case nil:

0 comments on commit 9bdff1f

Please sign in to comment.