Code cleanup.
This commit is contained in:
1 parent
92fd479336
commit
86cb2edb05
49 files changed
+433
-1020
No files matched your search
+11
-10
@@ -6,33 +6,34 @@
|
||||
package emoji
|
||||
|
||||
import (
|
||||
"git.stormux.org/storm/fenrir/internal/interaction"
|
||||
"git.stormux.org/storm/fenrir/internal/i18n"
|
||||
commonemoji "git.stormux.org/storm/screenreader-common/emoji"
|
||||
"git.stormux.org/storm/screenreader-common/internalui"
|
||||
)
|
||||
|
||||
const MenuTitle = "Emoji Menu"
|
||||
|
||||
// NewSession builds an independent draft. Search is local to each category;
|
||||
// the first All tab searches the complete catalog.
|
||||
func NewSession() (*interaction.Session, error) {
|
||||
form := interaction.Form{Type: interaction.TabForm, Title: MenuTitle}
|
||||
func NewSession() (*internalui.Session, error) {
|
||||
form := internalui.Form{Type: internalui.TabForm, Title: MenuTitle}
|
||||
for _, tab := range commonemoji.PickerTabs() {
|
||||
choices := make([]interaction.Choice, len(tab.Entries))
|
||||
choices := make([]internalui.Choice, len(tab.Entries))
|
||||
for index, entry := range tab.Entries {
|
||||
choices[index] = interaction.Choice{ID: entry.ID, Label: entry.Label}
|
||||
choices[index] = internalui.Choice{ID: entry.ID, Label: entry.Label}
|
||||
}
|
||||
form.Tabs = append(form.Tabs, interaction.Tab{ID: tab.ID, Label: tab.Label, Controls: []interaction.Control{{
|
||||
ID: "emoji", Label: "Emoji", Kind: interaction.Grid, Choices: choices, Columns: commonemoji.PickerColumns, Action: "copy_emoji",
|
||||
form.Tabs = append(form.Tabs, internalui.Tab{ID: tab.ID, Label: tab.Label, Controls: []internalui.Control{{
|
||||
ID: "emoji", Label: "Emoji", Kind: internalui.Grid, Choices: choices, Columns: commonemoji.PickerColumns, Action: "copy_emoji",
|
||||
}}})
|
||||
}
|
||||
return interaction.NewSession(form)
|
||||
return internalui.NewSession(form, internalui.Messages{Translate: i18n.T})
|
||||
}
|
||||
|
||||
// Selection returns the selected Unicode sequence and readable name. It never
|
||||
// returns a selection from another tab or from an empty search.
|
||||
func Selection(session *interaction.Session) (string, string, bool) {
|
||||
func Selection(session *internalui.Session) (string, string, bool) {
|
||||
control, ok := session.FocusedControl()
|
||||
if !ok || control.Kind != interaction.Grid || control.Selected < 0 || control.Selected >= len(control.Choices) {
|
||||
if !ok || control.Kind != internalui.Grid || control.Selected < 0 || control.Selected >= len(control.Choices) {
|
||||
return "", "", false
|
||||
}
|
||||
choice := control.Choices[control.Selected]
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"git.stormux.org/storm/fenrir/internal/i18n"
|
||||
"git.stormux.org/storm/fenrir/internal/interaction"
|
||||
commonemoji "git.stormux.org/storm/screenreader-common/emoji"
|
||||
"git.stormux.org/storm/screenreader-common/internalui"
|
||||
)
|
||||
|
||||
func TestCategorySelectionAndIndependentSearches(t *testing.T) {
|
||||
@@ -21,24 +21,24 @@ func TestCategorySelectionAndIndependentSearches(t *testing.T) {
|
||||
if _, _, ok := Selection(session); ok {
|
||||
t.Fatal("tab strip has a selection")
|
||||
}
|
||||
session.Handle(interaction.Key{Name: "tab"})
|
||||
session.Handle(interaction.Key{Text: "j"})
|
||||
session.Handle(interaction.Key{Name: "right"})
|
||||
session.Handle(internalui.Key{Name: "tab"})
|
||||
session.Handle(internalui.Key{Text: "j"})
|
||||
session.Handle(internalui.Key{Name: "right"})
|
||||
if value, _, _ := Selection(session); value != "🇯🇵" {
|
||||
t.Fatal("filtered All navigation", value)
|
||||
}
|
||||
session.Handle(interaction.Key{Name: "tab"})
|
||||
session.Handle(interaction.Key{Name: "right"})
|
||||
session.Handle(interaction.Key{Name: "right"})
|
||||
session.Handle(interaction.Key{Name: "tab"})
|
||||
session.Handle(interaction.Key{Text: "c"})
|
||||
session.Handle(internalui.Key{Name: "tab"})
|
||||
session.Handle(internalui.Key{Name: "right"})
|
||||
session.Handle(internalui.Key{Name: "right"})
|
||||
session.Handle(internalui.Key{Name: "tab"})
|
||||
session.Handle(internalui.Key{Text: "c"})
|
||||
if value, _, _ := Selection(session); value != "🐱" {
|
||||
t.Fatal("Nature selection came from another tab", value)
|
||||
}
|
||||
session.Handle(interaction.Key{Name: "tab", Shift: true})
|
||||
session.Handle(interaction.Key{Name: "left"})
|
||||
session.Handle(interaction.Key{Name: "left"})
|
||||
session.Handle(interaction.Key{Name: "tab"})
|
||||
session.Handle(internalui.Key{Name: "tab", Shift: true})
|
||||
session.Handle(internalui.Key{Name: "left"})
|
||||
session.Handle(internalui.Key{Name: "left"})
|
||||
session.Handle(internalui.Key{Name: "tab"})
|
||||
if value, _, _ := Selection(session); value != "🇯🇵" {
|
||||
t.Fatal("All search/selection not retained", value)
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func TestCategorySelectionAndIndependentSearches(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
other.Handle(interaction.Key{Name: "tab"})
|
||||
other.Handle(internalui.Key{Name: "tab"})
|
||||
control, controlOK := other.FocusedControl()
|
||||
value, _, selectionOK := Selection(other)
|
||||
if !controlOK || control.Text != "" || !selectionOK || value == "🇯🇵" {
|
||||
@@ -64,8 +64,8 @@ func TestBundledTranslationSearchPreservesEmoji(t *testing.T) {
|
||||
if got := session.Open(); !strings.HasPrefix(got, "Emoji-Menü. Alle Registerkarte") {
|
||||
t.Fatal("untranslated picker", got)
|
||||
}
|
||||
session.Handle(interaction.Key{Name: "tab"})
|
||||
session.Handle(interaction.Key{Text: "Schmetter"})
|
||||
session.Handle(internalui.Key{Name: "tab"})
|
||||
session.Handle(internalui.Key{Text: "Schmetter"})
|
||||
if value, label, ok := Selection(session); !ok || value != "🦋" || label != "Butterfly" {
|
||||
t.Fatalf("localized search changed identity: %q %q %v", value, label, ok)
|
||||
}
|
||||
@@ -121,8 +121,8 @@ func TestKissMarkSearch(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
session.Handle(interaction.Key{Name: "tab"})
|
||||
session.Handle(interaction.Key{Text: "Kiss mark"})
|
||||
session.Handle(internalui.Key{Name: "tab"})
|
||||
session.Handle(internalui.Key{Text: "Kiss mark"})
|
||||
if value, label, ok := Selection(session); !ok || value != "💋" || label != "Kiss mark" {
|
||||
t.Fatalf("kiss mark selection = %q %q %v", value, label, ok)
|
||||
}
|
||||
@@ -132,8 +132,8 @@ func TestKissMarkSearch(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
localized.Handle(interaction.Key{Name: "tab"})
|
||||
localized.Handle(interaction.Key{Text: "Kussabdruck"})
|
||||
localized.Handle(internalui.Key{Name: "tab"})
|
||||
localized.Handle(internalui.Key{Text: "Kussabdruck"})
|
||||
if value, _, ok := Selection(localized); !ok || value != "💋" {
|
||||
t.Fatalf("localized kiss mark selection = %q %v", value, ok)
|
||||
}
|
||||
@@ -145,9 +145,9 @@ func TestNewCategoryNavigation(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for range 4 {
|
||||
session.Handle(interaction.Key{Name: "right"})
|
||||
session.Handle(internalui.Key{Name: "right"})
|
||||
}
|
||||
session.Handle(interaction.Key{Name: "tab"})
|
||||
session.Handle(internalui.Key{Name: "tab"})
|
||||
if value, label, ok := Selection(session); !ok || value != "⚽" || label != "Soccer ball" {
|
||||
t.Fatalf("Activity navigation failed: %q %q %v", value, label, ok)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user