~sircmpwn/aerc

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

[PATCH] Allow fields in compose widget to be clicked

Details
Message ID
<20191106034345.79146-1-greg@gpanders.com>
DKIM signature
missing
Download raw message
Patch: +32 -2
When the mouse is enabled, clicking on a header field switches focus to
that field (likewise for the terminal).
---
 widgets/compose.go | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/widgets/compose.go b/widgets/compose.go
index 22c58da..b9f0932 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -289,6 +289,16 @@ func (c *Composer) Event(event tcell.Event) bool {
 	return false
 }
 
+func (c *Composer) MouseEvent(localX int, localY int, event tcell.Event) {
+	c.grid.MouseEvent(localX, localY, event)
+	for _, e := range c.focusable {
+		he, ok := e.(*headerEditor)
+		if ok && he.focused {
+			c.FocusEditor(he)
+		}
+	}
+}
+
 func (c *Composer) Focus(focus bool) {
 	c.focusable[c.focused].Focus(focus)
 }
@@ -544,6 +554,18 @@ func (c *Composer) resetReview() {
 	}
 }
 
+func (c *Composer) termEvent(event tcell.Event) bool {
+	switch event := event.(type) {
+	case *tcell.EventMouse:
+		switch event.Buttons() {
+		case tcell.Button1:
+			c.FocusTerminal()
+			return true
+		}
+	}
+	return false
+}
+
 func (c *Composer) termClosed(err error) {
 	c.grid.RemoveChild(c.editor)
 	c.review = newReviewMessage(c, err)
@@ -572,6 +594,7 @@ func (c *Composer) ShowTerminal() {
 	}
 	editor := exec.Command("/bin/sh", "-c", editorName+" "+c.email.Name())
 	c.editor, _ = NewTerminal(editor) // TODO: handle error
+	c.editor.OnEvent = c.termEvent
 	c.editor.OnClose = c.termClosed
 	c.grid.AddChild(c.editor).At(1, 0)
 	c.focusable = append(c.focusable, c.editor)
@@ -665,8 +688,9 @@ func (c *Composer) reloadEmail() error {
 }
 
 type headerEditor struct {
-	name  string
-	input *ui.TextInput
+	name    string
+	focused bool
+	input   *ui.TextInput
 }
 
 func newHeaderEditor(name string, value string) *headerEditor {
@@ -687,6 +711,11 @@ func (he *headerEditor) Draw(ctx *ui.Context) {
 func (he *headerEditor) MouseEvent(localX int, localY int, event tcell.Event) {
 	switch event := event.(type) {
 	case *tcell.EventMouse:
+		switch event.Buttons() {
+		case tcell.Button1:
+			he.focused = true
+		}
+
 		width := runewidth.StringWidth(he.name + " ")
 		if localX >= width {
 			he.input.MouseEvent(localX-width, localY, event)
@@ -705,6 +734,7 @@ func (he *headerEditor) OnInvalidate(fn func(ui.Drawable)) {
 }
 
 func (he *headerEditor) Focus(focused bool) {
+	he.focused = focused
 	he.input.Focus(focused)
 }
 
-- 
2.24.0
Details
Message ID
<20191106034515.n24sdplxzfzoehp2@Kepler>
In-Reply-To
<20191106034345.79146-1-greg@gpanders.com> (view parent)
DKIM signature
missing
Download raw message
I forgot to mention that this is meant to address ticket #299.

On Tue, 05 Nov 2019 at 08:43 PM, Greg Anders wrote:
>When the mouse is enabled, clicking on a header field switches focus to
>that field (likewise for the terminal).
>---
> widgets/compose.go | 34 ++++++++++++++++++++++++++++++++--
> 1 file changed, 32 insertions(+), 2 deletions(-)
>
>diff --git a/widgets/compose.go b/widgets/compose.go
>index 22c58da..b9f0932 100644
>--- a/widgets/compose.go
>+++ b/widgets/compose.go
>@@ -289,6 +289,16 @@ func (c *Composer) Event(event tcell.Event) bool {
> 	return false
> }
>
>+func (c *Composer) MouseEvent(localX int, localY int, event tcell.Event) {
>+	c.grid.MouseEvent(localX, localY, event)
>+	for _, e := range c.focusable {
>+		he, ok := e.(*headerEditor)
>+		if ok && he.focused {
>+			c.FocusEditor(he)
>+		}
>+	}
>+}
>+
> func (c *Composer) Focus(focus bool) {
> 	c.focusable[c.focused].Focus(focus)
> }
>@@ -544,6 +554,18 @@ func (c *Composer) resetReview() {
> 	}
> }
>
>+func (c *Composer) termEvent(event tcell.Event) bool {
>+	switch event := event.(type) {
>+	case *tcell.EventMouse:
>+		switch event.Buttons() {
>+		case tcell.Button1:
>+			c.FocusTerminal()
>+			return true
>+		}
>+	}
>+	return false
>+}
>+
> func (c *Composer) termClosed(err error) {
> 	c.grid.RemoveChild(c.editor)
> 	c.review = newReviewMessage(c, err)
>@@ -572,6 +594,7 @@ func (c *Composer) ShowTerminal() {
> 	}
> 	editor := exec.Command("/bin/sh", "-c", editorName+" "+c.email.Name())
> 	c.editor, _ = NewTerminal(editor) // TODO: handle error
>+	c.editor.OnEvent = c.termEvent
> 	c.editor.OnClose = c.termClosed
> 	c.grid.AddChild(c.editor).At(1, 0)
> 	c.focusable = append(c.focusable, c.editor)
>@@ -665,8 +688,9 @@ func (c *Composer) reloadEmail() error {
> }
>
> type headerEditor struct {
>-	name  string
>-	input *ui.TextInput
>+	name    string
>+	focused bool
>+	input   *ui.TextInput
> }
>
> func newHeaderEditor(name string, value string) *headerEditor {
>@@ -687,6 +711,11 @@ func (he *headerEditor) Draw(ctx *ui.Context) {
> func (he *headerEditor) MouseEvent(localX int, localY int, event tcell.Event) {
> 	switch event := event.(type) {
> 	case *tcell.EventMouse:
>+		switch event.Buttons() {
>+		case tcell.Button1:
>+			he.focused = true
>+		}
>+
> 		width := runewidth.StringWidth(he.name + " ")
> 		if localX >= width {
> 			he.input.MouseEvent(localX-width, localY, event)
>@@ -705,6 +734,7 @@ func (he *headerEditor) OnInvalidate(fn func(ui.Drawable)) {
> }
>
> func (he *headerEditor) Focus(focused bool) {
>+	he.focused = focused
> 	he.input.Focus(focused)
> }
>
>-- 
>2.24.0
>
Jonathan Dowland
Details
Message ID
<BYASWKMROOXI.1V4TYU2EJ2J7N@qusp>
In-Reply-To
<20191106034345.79146-1-greg@gpanders.com> (view parent)
DKIM signature
missing
Download raw message
On Tue Nov 5, 2019 at 8:43 PM Greg Anders wrote:
> When the mouse is enabled, clicking on a header field switches focus to
> that field (likewise for the terminal).

This is nice. Some improvements might be: it would be good if clicking
in the label region (e.g. "To", "Subject") also focussed the
corresponding input region. But as it stands still a major improvement
IMHO!
Details
Message ID
<BYIDR4NE5O4Y.3QV9Q82M1GFZ2@homura>
In-Reply-To
<20191106034345.79146-1-greg@gpanders.com> (view parent)
DKIM signature
pass
Download raw message
Thanks!

To git.sr.ht:~sircmpwn/aerc
   8a84830..3338dce  master -> master