~eliasnaur/gio-patches

widget: no newline in editor on submit v1 PROPOSED

Larry Clapp: 1
 widget: no newline in editor on submit

 1 files changed, 2 insertions(+), 1 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/~eliasnaur/gio-patches/patches/9020/mbox | git am -3
Learn more about email & git

[PATCH] widget: no newline in editor on submit Export this patch

When you press enter to "submit" an editor widget, don't also append the
newline to the editor text.  Enter should be "submit" or "add newline"
but not both.

Also add parens to the Enter check: x && y || z => x && (y || z).

Signed-off-by: Larry Clapp <larry@theclapp.org>
---
 widget/editor.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/widget/editor.go b/widget/editor.go
index 6c2a64d..6e63f92 100644
--- a/widget/editor.go
+++ b/widget/editor.go
@@ -153,11 +153,12 @@ func (e *Editor) processKey(gtx *layout.Context) {
 			if !e.focused {
 				break
 			}
-			if e.Submit && ke.Name == key.NameReturn || ke.Name == key.NameEnter {
+			if e.Submit && (ke.Name == key.NameReturn || ke.Name == key.NameEnter) {
 				if !ke.Modifiers.Contain(key.ModShift) {
 					e.events = append(e.events, SubmitEvent{
 						Text: e.Text(),
 					})
+					return
 				}
 			}
 			if e.command(ke) {
-- 
2.23.0
Thanks!
View this thread in the archives