shithub: mycel

Download patch

ref: 52fda39dd18e9e6f1397c477980cf20fcf8e172f
parent: c1790ce4d49b170660e641d9b8a3b923dde2c269
author: Philip Silva <philip.silva@protonmail.com>
date: Thu Feb 11 15:12:34 EST 2021

fix double-boxing of text area

--- a/browser/browser.go
+++ b/browser/browser.go
@@ -401,13 +401,11 @@
 	}
 	edit.Append([]byte(formatted))
 
-	el := NewElement(
-		&duit.Box{
-			Kids:   duit.NewKids(edit),
-			Height: (int(n.FontSize()) + 4) * (len(lines)+2),
-		},
-		n,
-	)
+	if n.Css("height") == "" {
+		n.SetCss("height", fmt.Sprintf("%vpx", (int(n.FontSize()) + 4) * (len(lines)+2)))
+	}
+
+	el := NewElement(edit, n)
 	el.Changed = func(e *Element) {
 		ed := e.UI.(*duit.Box).Kids[0].UI.(*duit.Edit)
 
--- a/browser/browser_test.go
+++ b/browser/browser_test.go
@@ -1,9 +1,11 @@
 package browser
 
 import (
+	"9fans.net/go/draw"
 	"fmt"
 	"github.com/mjl-/duit"
 	"golang.org/x/net/html"
+	"image"
 	"net/http"
 	"net/url"
 	"github.com/chris-ramon/douceur/css"
@@ -311,3 +313,18 @@
 func TestAlwaysOneElement(t *testing.T) {
 }
 
+func TestTextArea(t *testing.T) {
+	htm := `
+		<textarea height="100">
+		</textarea>
+	`
+	nt, _, err := digestHtm(htm)
+	if err != nil {
+		t.Fatalf("digest: %v", err)
+	}
+
+	ta := nt.Find("textarea")
+	el := NewTextArea(ta)
+	// Trigger key press to trigger call to changed
+	el.Key(nil, nil, 'a', draw.Mouse{}, image.Point{})
+}
--- a/style/stylesheets.go
+++ b/style/stylesheets.go
@@ -512,7 +512,7 @@
 			s.Left = nums[3]
 		}
 	}
-	
+
 	if t, err := cs.CssPx(key+"-top"); err == nil {
 		s.Top = t
 	}
@@ -613,4 +613,11 @@
 	}
 	l = int(f)
 	return
+}
+
+func (cs Map) SetCss(k, v string) {
+	cs.Declarations[k] = css.Declaration{
+		Property: k,
+		Value: v,
+	}
 }