@@ -3,6 +3,7 @@ package readline
33import (
44 "fmt"
55 "io"
6+ "slices"
67 "sort"
78 "strings"
89 "unicode"
@@ -12,6 +13,7 @@ import (
1213 "github.com/reeflective/readline/inputrc"
1314 "github.com/reeflective/readline/internal/color"
1415 "github.com/reeflective/readline/internal/completion"
16+ "github.com/reeflective/readline/internal/core"
1517 "github.com/reeflective/readline/internal/keymap"
1618 "github.com/reeflective/readline/internal/strutil"
1719 "github.com/reeflective/readline/internal/term"
@@ -448,8 +450,27 @@ func (rl *Shell) selfInsert() {
448450}
449451
450452func (rl * Shell ) bracketedPasteBegin () {
451- // keys, _ := rl.Keys.PeekAllBytes()
452- // fmt.Println(string(keys))
453+ // Length of bracketed paste escape code; this is the minimum length
454+ // we will see here.
455+ sequence := make ([]byte , 0 , 6 )
456+
457+ for {
458+ key , empty := core .PopKey (rl .Keys )
459+ if empty {
460+ core .WaitAvailableKeys (rl .Keys , rl .Config )
461+ continue
462+ }
463+
464+ sequence = append (sequence , key )
465+
466+ if len (sequence ) >= 6 && slices .Equal (sequence [len (sequence )- 6 :], []byte {'\x1b' , '[' , '2' , '0' , '1' , '~' }) {
467+ break
468+ }
469+ }
470+
471+ if len (sequence ) > 6 {
472+ rl .cursor .InsertAt ([]rune (string (sequence [:len (sequence )- 6 ]))... )
473+ }
453474}
454475
455476// Drag the character before point forward over the character
0 commit comments