Typing de lists the German locales rather than Denmark first; each row shows a number, a date and a formula as the locale writes them, and the first, Default, says which locale the setting gives.
- commit
- 411dbe1b18da1f5caa253bdc4a0ddc73ab4c2f97
- parent
- 87a90772190e505287440953004c1d0295063134
- author
- Dami <dami.etoile@gmail.com>
| M | internal/ | 33 | +++++++++++++++++++++++++----- |
@@ -1,6 +1,8 @@
11 package ui22 33 import (4+ "strings"5+46 tea "charm.land/bubbletea/v2"57 68 "github.com/FelineStateMachine/012/internal/formula"@@ -56,7 +58,8 @@ func (m *Model) canPoint() bool {
5658 func (m *Model) openLocalePicker() {5759 cur := m.book().LocaleTag()5860 def := sheet.DefaultLocale()59- items := []picker.Item{m.localeItem("Default: "+def.Name, "", def)}61+ items := []picker.Item{m.localeItem("Default", "", def)}62+ items[0].Desc = "Follow the locale setting, " + def.Name + ". " + localeDesc(def)6063 sel := 06164 for i, l := range locale.All() {6265 if l.Tag == cur {@@ -64,13 +67,30 @@ func (m *Model) openLocalePicker() {
6467 }6568 items = append(items, m.localeItem(l.Name, l.Tag, l))6669 }67- p := m.newPicker("Locale", "Type a language, country or tag", 72, items)70+ p := m.newPicker("Locale", "Type a language, country or tag", 80, items)6871 p.Action = "set"6972 p.Answers = true7073 p.Sel = sel74+ p.Narrow = narrowTags7175 m.openOverlay(p)7276 }7377 78+// narrowTags keeps the locales whose tag starts with the search, when79+// any does: "de" lists German ones rather than Denmark first.80+func narrowTags(query string) (string, func(*picker.Item) bool) {81+ q := strings.ToLower(strings.TrimSpace(query))82+ if len(q) < 2 {83+ return query, nil84+ }85+ tagged := func(it *picker.Item) bool { return strings.HasPrefix(strings.ToLower(it.Detail), q) }86+ for _, tag := range locale.Tags() {87+ if strings.HasPrefix(strings.ToLower(tag), q) {88+ return "", tagged89+ }90+ }91+ return query, nil92+}93+7494 // localeItem is the picker's row for l, which picking sets as tag.7595 func (m *Model) localeItem(title, tag string, l *locale.Locale) picker.Item {7696 return picker.Item{@@ -83,17 +103,20 @@ func (m *Model) localeItem(title, tag string, l *locale.Locale) picker.Item {
83103 }84104 }85105 86-// localeSample shows a number, a date and the argument separator in l.106+// localeSample shows a number, a date and a formula in l.87107 func localeSample(l *locale.Locale) string {88- return numfmt.FormatIn(1234.56, "#,##0.00", l) + " " + numfmt.FormatIn(sampleDate, l.Date, l) + " " + string(l.ArgSep())108+ return numfmt.FormatIn(1234.56, "#,##0.00", l) + " " + numfmt.FormatIn(sampleDate, l.Date, l) + " " + sampleFormula(l)89109 }90110 91111 // localeDesc says how l writes currency, dates and formulas.92112 func localeDesc(l *locale.Locale) string {93113 return "Numbers " + numfmt.FormatIn(1234.56, sheet.Preset(sheet.FmtCurrency).CodeIn(l), l) +94- ", dates " + numfmt.FormatIn(sampleDate, l.Date, l) + ", formulas =ROUND(A1" + string(l.ArgSep()) + " 2)"114+ ", dates " + numfmt.FormatIn(sampleDate, l.Date, l) + ", formulas " + sampleFormula(l)95115 }96116 117+// sampleFormula is a formula with a decimal and two arguments, in l.118+func sampleFormula(l *locale.Locale) string { return formula.Localize("=ROUND(1.5, 1)", l) }119+97120 // sampleDate is the date locales are shown with.98121 var sampleDate = numfmt.DateSerial(2026, 9, 26)99122