widget: [API] re-implement Editor.Focus in terms of commands

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-10-20 20:55:56 -05:00
parent 5dd41f74d3
commit 8334d2abb4
3 changed files with 16 additions and 21 deletions
+7 -7
View File
@@ -115,7 +115,7 @@ func TestEditorReadOnly(t *testing.T) {
if cStart != cEnd {
t.Errorf("unexpected initial caret positions")
}
e.Focus()
e.Focus(gtx)
layoutEditor := func() layout.Dimensions {
return e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
}
@@ -511,7 +511,7 @@ func TestEditorDimensions(t *testing.T) {
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
fontSize := unit.Sp(10)
font := font.Font{}
e.Focus()
e.Focus(gtx)
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
r.Frame(gtx.Ops)
r.Queue(key.EditEvent{Text: "A"})
@@ -904,7 +904,7 @@ g 2 4 6 8 g
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
e.Events() // throw away any events from this layout
e.Focus()
e.Focus(gtx)
r.Frame(gtx.Ops)
gtx.Source = r.Source()
// Build the selection events
@@ -998,7 +998,7 @@ func TestSelectMove(t *testing.T) {
fontSize := unit.Sp(10)
// Layout once to populate e.lines and get focus.
e.Focus()
e.Focus(gtx)
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
r.Frame(gtx.Ops)
// Set up selecton so the Editor key handler filters for all 4 directional keys.
@@ -1085,7 +1085,7 @@ func TestEditor_MaxLen(t *testing.T) {
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
fontSize := unit.Sp(10)
font := font.Font{}
e.Focus()
e.Focus(gtx)
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
r.Frame(gtx.Ops)
r.Queue(
@@ -1121,7 +1121,7 @@ func TestEditor_Filter(t *testing.T) {
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
fontSize := unit.Sp(10)
font := font.Font{}
e.Focus()
e.Focus(gtx)
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
r.Frame(gtx.Ops)
r.Queue(
@@ -1151,7 +1151,7 @@ func TestEditor_Submit(t *testing.T) {
cache := text.NewShaper(text.NoSystemFonts(), text.WithCollection(gofont.Collection()))
fontSize := unit.Sp(10)
font := font.Font{}
e.Focus()
e.Focus(gtx)
e.Layout(gtx, cache, font, fontSize, op.CallOp{}, op.CallOp{})
r.Frame(gtx.Ops)
r.Queue(