~delthas/senpai-dev

Add showing newlines in pasted content v1 APPLIED

ptrcnull: 1
 Add showing newlines in pasted content

 3 files changed, 24 insertions(+), 10 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~delthas/senpai-dev/patches/44245/mbox | git am -3
Learn more about email & git

[PATCH v1] Add showing newlines in pasted content Export this patch

---
 app.go       | 24 +++++++++++++++---------
 ui/editor.go |  7 ++++++-
 ui/style.go  |  3 +++
 3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/app.go b/app.go
index 509a518..db57e0f 100644
--- a/app.go
+++ b/app.go
@@ -653,17 +653,23 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
	case tcell.KeyF8:
		app.win.ToggleMemberList()
	case tcell.KeyCR, tcell.KeyLF:
		if app.pasting {
			app.win.InputRune('\n')
			break
		}
		netID, buffer := app.win.CurrentBuffer()
		input := app.win.InputEnter()
		err := app.handleInput(buffer, input)
		if err != nil {
			app.win.AddLine(netID, buffer, ui.Line{
				At:        time.Now(),
				Head:      "!!",
				HeadColor: tcell.ColorRed,
				Notify:    ui.NotifyUnread,
				Body:      ui.PlainSprintf("%q: %s", input, err),
			})
		for _, part := range strings.Split(input, "\n") {
			err := app.handleInput(buffer, part)
			if err != nil {
				app.win.AddLine(netID, buffer, ui.Line{
					At:        time.Now(),
					Head:      "!!",
					HeadColor: tcell.ColorRed,
					Notify:    ui.NotifyUnread,
					Body:      ui.PlainSprintf("%q: %s", part, err),
				})
			}
		}
	case tcell.KeyRune:
		if ev.Modifiers() == tcell.ModAlt {
diff --git a/ui/editor.go b/ui/editor.go
index a63438d..a3f545f 100644
--- a/ui/editor.go
+++ b/ui/editor.go
@@ -453,7 +453,12 @@ func (e *Editor) Draw(screen tcell.Screen, x0, y int) {
		if e.backsearch && i < e.cursorIdx && i >= e.cursorIdx-len(e.backsearchPattern) {
			s = s.Underline(true)
		}
		screen.SetContent(x, y, r, nil, s)
		if r == '\n' {
			style := tcell.StyleDefault.Background(tcell.ColorRed).Foreground(tcell.ColorBlack)
			screen.SetCell(x, y, style, '↲')
		} else {
			screen.SetContent(x, y, r, nil, s)
		}
		x += runeWidth(r)
		i++
	}
diff --git a/ui/style.go b/ui/style.go
index 9a662e3..dc9905c 100644
--- a/ui/style.go
+++ b/ui/style.go
@@ -17,6 +17,9 @@ import (
var condition = runewidth.Condition{}

func runeWidth(r rune) int {
	if r == '\n' {
		r = '↲'
	}
	return condition.RuneWidth(r)
}


base-commit: 21fcd224499af076398ab89e2602de58405c3acc
-- 
2.42.0
Hi,

Thanks for your patch :-)

FTR I'd like to have a proper multi-line editor, but having this in the 
meantime is much better than the current behavior where you can 
accidentally flood a channel on a bad CTRL+V.

Applied with small code style changes.

To git.sr.ht:~delthas/senpai
    d6230f3..1c49cca  master -> master