From 5bd6dd90bdd6d867bfb5d7fe2dd2e60e8e91e726 Mon Sep 17 00:00:00 2001 From: ptrcnull Date: Wed, 4 May 2022 23:29:44 +0200 Subject: [PATCH 1/4] Add showing newlines in pasted content Slightly modified by @Consolatis - Version 1 Don't hardcode length of LF rune - Version 2 rebase on master and handle InputFlush() --- app.go | 27 ++++++++++++++++++--------- ui/editor.go | 4 ++++ ui/style.go | 3 +++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app.go b/app.go index d4c58ef..b8a2af5 100644 --- a/app.go +++ b/app.go @@ -671,17 +671,26 @@ 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 := string(app.win.InputContent()) - if err := app.handleInput(buffer, input); 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), - }) - } else { + errs := false + for _, part := range strings.Split(input, "\n") { + if err := app.handleInput(buffer, part); err != nil { + errs = true + app.win.AddLine(netID, buffer, ui.Line{ + At: time.Now(), + Head: "!!", + HeadColor: tcell.ColorRed, + Notify: ui.NotifyUnread, + Body: ui.PlainSprintf("%q: %s", part, err), + }) + } + } + if errs == false { app.win.InputFlush() } case tcell.KeyRune: diff --git a/ui/editor.go b/ui/editor.go index 9b8116d..7b90627 100644 --- a/ui/editor.go +++ b/ui/editor.go @@ -490,6 +490,10 @@ func (e *Editor) Draw(screen tcell.Screen, x0, y int, hint string) { if i == autoStart { autoX = x } + if r == '\n' { + r = '↲' + s = s.Background(tcell.ColorRed).Foreground(tcell.ColorBlack) + } screen.SetContent(x, y, r, nil, s) x += runeWidth(r) i++ diff --git a/ui/style.go b/ui/style.go index 38f2d2c..836bc18 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) } From ffaf3820c8946789ce3a1783603c698bd552122c Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Mon, 11 Mar 2024 02:46:54 +0100 Subject: [PATCH 2/4] ui/editor.go: make the auto complete popup a box --- ui/editor.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/ui/editor.go b/ui/editor.go index 7b90627..4c0567f 100644 --- a/ui/editor.go +++ b/ui/editor.go @@ -525,6 +525,7 @@ func (e *Editor) Draw(screen tcell.Screen, x0, y int, hint string) { } } + pad_rune := rune(' ') for i, completion := range e.autoCache[autoOff : autoOff+autoCount] { display := completion.Display if display == nil { @@ -533,20 +534,27 @@ func (e *Editor) Draw(screen tcell.Screen, x0, y int, hint string) { x := autoX y := y - i - 1 + + s := st.Background(tcell.ColorBlack) + s = s.Reverse(i+autoOff == e.autoCacheIdx) + + /* Pad one space at the left */ + screen.SetContent(x, y, pad_rune, nil, s) + x += runeWidth(pad_rune) + for _, r := range display { - if x >= x0+e.width { + if x + 1 >= x0+e.width { break } - s := st.Background(tcell.ColorBlack) - s = s.Reverse(true) - if i+autoOff == e.autoCacheIdx { - s = s.Bold(true) - } else { - s = s.Dim(true) - } screen.SetContent(x, y, r, nil, s) x += runeWidth(r) } + + /* Pad to the right so we get to 20 in total */ + for (x - autoX) < 20 && x < x0+e.width { + screen.SetContent(x, y, pad_rune, nil, s) + x += runeWidth(pad_rune) + } } if showCursor { From 31e7bb3992e0028baa6fc3eac20a5b34504d9779 Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:36:08 +0100 Subject: [PATCH 3/4] ui/editor.go: auto complete directly if there is just one --- ui/editor.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/editor.go b/ui/editor.go index 4c0567f..eafd01b 100644 --- a/ui/editor.go +++ b/ui/editor.go @@ -388,7 +388,9 @@ func (e *Editor) AutoComplete() (ok bool) { return false } e.autoCacheIdx = 0 - return + if len(e.autoCache) > 1 { + return + } } e.text[e.lineIdx] = e.autoCache[e.autoCacheIdx].Text From 3d418ee4c89f54f14251b7e265ea4e017b246ca0 Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Thu, 14 Mar 2024 05:50:29 +0100 Subject: [PATCH 4/4] ui/editor.go: reverse rendering order for autocomplete --- ui/editor.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/editor.go b/ui/editor.go index eafd01b..1997532 100644 --- a/ui/editor.go +++ b/ui/editor.go @@ -347,7 +347,7 @@ func (e *Editor) End() { func (e *Editor) Up() { if e.autoCache != nil { - e.autoCacheIdx = (e.autoCacheIdx + 1) % len(e.autoCache) + e.autoCacheIdx = (e.autoCacheIdx + len(e.autoCache) - 1) % len(e.autoCache) return } if e.lineIdx == 0 { @@ -364,7 +364,7 @@ func (e *Editor) Up() { func (e *Editor) Down() { if e.autoCache != nil { - e.autoCacheIdx = (e.autoCacheIdx + len(e.autoCache) - 1) % len(e.autoCache) + e.autoCacheIdx = (e.autoCacheIdx + 1) % len(e.autoCache) return } if e.lineIdx == len(e.text)-1 { @@ -535,7 +535,7 @@ func (e *Editor) Draw(screen tcell.Screen, x0, y int, hint string) { } x := autoX - y := y - i - 1 + y := y - (autoCount - i) s := st.Background(tcell.ColorBlack) s = s.Reverse(i+autoOff == e.autoCacheIdx)