commit 1c49cca
ptrcnull
·
2023-08-31 13:37:14 +0000 UTC
parent d6230f3
Edit multi-line pasted content before sending it This avoids accidentally sending multiple lines on an unexpected clipboard paste.
3 files changed,
+25,
-9
M
app.go
+18,
-9
1@@ -745,17 +745,26 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
2 case tcell.KeyF8:
3 app.win.ToggleMemberList()
4 case tcell.KeyCR, tcell.KeyLF:
5+ if app.pasting {
6+ app.win.InputRune('\n')
7+ break
8+ }
9 netID, buffer := app.win.CurrentBuffer()
10 input := string(app.win.InputContent())
11- if err := app.handleInput(buffer, input); err != nil {
12- app.win.AddLine(netID, buffer, ui.Line{
13- At: time.Now(),
14- Head: "!!",
15- HeadColor: tcell.ColorRed,
16- Notify: ui.NotifyUnread,
17- Body: ui.PlainSprintf("%q: %s", input, err),
18- })
19- } else {
20+ var err error
21+ for _, part := range strings.Split(input, "\n") {
22+ if err = app.handleInput(buffer, part); err != nil {
23+ app.win.AddLine(netID, buffer, ui.Line{
24+ At: time.Now(),
25+ Head: "!!",
26+ HeadColor: tcell.ColorRed,
27+ Notify: ui.NotifyUnread,
28+ Body: ui.PlainSprintf("%q: %s", input, err),
29+ })
30+ break
31+ }
32+ }
33+ if err == nil {
34 app.win.InputFlush()
35 }
36 case tcell.KeyRune:
+4,
-0
1@@ -490,6 +490,10 @@ func (e *Editor) Draw(screen tcell.Screen, x0, y int, hint string) {
2 if i == autoStart {
3 autoX = x
4 }
5+ if r == '\n' {
6+ s = s.Bold(true).Foreground(tcell.ColorRed)
7+ r = '↲'
8+ }
9 screen.SetContent(x, y, r, nil, s)
10 x += runeWidth(r)
11 i++
+3,
-0
1@@ -17,6 +17,9 @@ import (
2 var condition = runewidth.Condition{}
3
4 func runeWidth(r rune) int {
5+ if r == '\n' {
6+ r = '↲'
7+ }
8 return condition.RuneWidth(r)
9 }
10