mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
widget: report SubmitEvents for IME newlines in submit mode
Before this change, an IME text edit would always have its newlines replaced with spaces. However, for Editors where Submit is enabled we want newlines to result in SubmitEvents. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -1067,6 +1067,35 @@ func TestEditor_Filter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEditor_Submit(t *testing.T) {
|
||||
e := new(Editor)
|
||||
e.Submit = true
|
||||
|
||||
gtx := layout.Context{
|
||||
Ops: new(op.Ops),
|
||||
Constraints: layout.Exact(image.Pt(100, 100)),
|
||||
Queue: newQueue(
|
||||
key.EditEvent{Range: key.Range{Start: 0, End: 0}, Text: "ab1\n"},
|
||||
),
|
||||
}
|
||||
cache := text.NewCache(gofont.Collection())
|
||||
fontSize := unit.Sp(10)
|
||||
font := text.Font{}
|
||||
e.Layout(gtx, cache, font, fontSize, nil)
|
||||
|
||||
if got, want := e.Text(), "ab1"; got != want {
|
||||
t.Errorf("editor failed to filter newline")
|
||||
}
|
||||
got := e.Events()
|
||||
want := []EditorEvent{
|
||||
ChangeEvent{},
|
||||
SubmitEvent{Text: e.Text()},
|
||||
}
|
||||
if !reflect.DeepEqual(want, got) {
|
||||
t.Errorf("editor failed to register submit")
|
||||
}
|
||||
}
|
||||
|
||||
func textWidth(e *Editor, lineNum, colStart, colEnd int) float32 {
|
||||
var w fixed.Int26_6
|
||||
glyphs := e.lines[lineNum].Layout.Glyphs
|
||||
|
||||
Reference in New Issue
Block a user