cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

Go to accepts a region's name (nu.r1) and selects its table

Dami committed 415bbd4
Go to parsed cells, ranges and named ranges only, so the names formulas
use for regions were refused. It now looks a nu. name up among the
workbook's regions and selects the table, header row included, on the
region's sheet.
commit
415bbd4a3b293cb95e93c5ee0a11df4117c86306
parent
d9a93a36b15ece3b6874d93bef43f86fb9c3d35d
author
Dami <dami.etoile@gmail.com>
kind
feat risk score 1.1 of 3, Jev's estimate
6 files changed, +71 -8
Mdocs/reference/keys.md2+-
Me2e/screenlist_test.go2+-
Me2e/testdata/screens/error-goto.html2+-
Ainternal/ui/goto_test.go42++++++++++++++++++++++++++++++
Minternal/ui/names_test.go2+-
Minternal/ui/selection.go29++++++++++++++++++---
M docs/reference/keys.md +1 -1
M e2e/screenlist_test.go +1 -1
M e2e/testdata/screens/error-goto.html +1 -1
@@ -27,4 +27,4 @@
2727 <span style="background:var(--vt-palette-8)"> </span><span style="color:var(--vt-palette-15);background:var(--vt-palette-8)">23</span><span style="background:var(--vt-palette-8)"> </span>2828 <span style="background:var(--vt-palette-8)"> </span><span style="color:var(--vt-palette-15);background:var(--vt-palette-8)">24</span><span style="background:var(--vt-palette-8)"> </span>2929 <span style="background:var(--vt-palette-8)"> </span><span style="color:var(--vt-palette-15);background:var(--vt-palette-8)">25</span><span style="background:var(--vt-palette-8)"> </span>30-<span style="color:var(--vt-palette-9);font-weight:bold">Not</span> <span style="color:var(--vt-palette-9);font-weight:bold">a</span> <span style="color:var(--vt-palette-9);font-weight:bold">cell,</span> <span style="color:var(--vt-palette-9);font-weight:bold">range</span> <span style="color:var(--vt-palette-9);font-weight:bold">or</span> <span style="color:var(--vt-palette-9);font-weight:bold">named</span> <span style="color:var(--vt-palette-9);font-weight:bold">range:</span> <span style="color:var(--vt-palette-9);font-weight:bold">nope</span> <span style="color:var(--vt-palette-8)">press</span> <span style="color:var(--vt-palette-8)">any</span> <span style="color:var(--vt-palette-8)">key</span></pre>\ No newline at end of file30+<span style="color:var(--vt-palette-9);font-weight:bold">Not</span> <span style="color:var(--vt-palette-9);font-weight:bold">a</span> <span style="color:var(--vt-palette-9);font-weight:bold">cell,</span> <span style="color:var(--vt-palette-9);font-weight:bold">range,</span> <span style="color:var(--vt-palette-9);font-weight:bold">named</span> <span style="color:var(--vt-palette-9);font-weight:bold">range</span> <span style="color:var(--vt-palette-9);font-weight:bold">or</span> <span style="color:var(--vt-palette-9);font-weight:bold">region:</span> <span style="color:var(--vt-palette-9);font-weight:bold">nope</span> <span style="color:var(--vt-palette-8)">press</span> <span style="color:var(--vt-palette-8)">any</span> <span style="color:var(--vt-palette-8)">key</span></pre>\ No newline at end of file
A internal/ui/goto_test.go +42 -0
M internal/ui/names_test.go +1 -1
M internal/ui/selection.go +25 -4
@@ -258,16 +258,16 @@ func isMoveKey(key string) bool {
258258 func (m *Model) openGoto() {259259 m.openText("Go to:", m.cur.String(), func(m *Model, text string) tea.Cmd {260260 if !m.gotoText(strings.TrimSpace(text)) {261- m.fail("Not a cell, range or named range: " + text)261+ m.fail("Not a cell, range, named range or region: " + text)262262 }263263 return nil264264 })265265 m.prompt.indicator = "POINT"266266 }267267 268-// gotoText goes to a cell, range or named range, on any sheet, and269-// reports whether text named one. A sheet may lead: Sheet2!A1,270-// 'Q3 plan'!B2:C9, or just Sheet2!.268+// gotoText goes to a cell, range, named range or region's table (nu.r1,269+// as formulas name it), on any sheet, and reports whether text named270+// one. A sheet may lead: Sheet2!A1, 'Q3 plan'!B2:C9, or just Sheet2!.271271 func (m *Model) gotoText(text string) bool {272272 target := m.sheet273273 if name, rest := sheet.SplitSheet(text); name != "" {
@@ -286,6 +286,9 @@ func (m *Model) gotoText(text string) bool {
286286 if n, named := m.sheet.LookupName(text); named && !n.Gone() && target == m.sheet {287287 r, ok, target = n.Range, true, n.Sheet288288 }289+ if !ok && target == m.sheet {290+ r, target, ok = m.regionTable(text)291+ }289292 if !ok {290293 return false291294 }
@@ -301,3 +304,21 @@ func (m *Model) gotoText(text string) bool {
301304 m.selectRect(r)302305 return true303306 }307+308+// regionTable finds the region formulas name as text (nu.r1), ignoring309+// case, and returns its table, header row included, and its sheet. A310+// region not run yet has no table: its label line stands for it.311+func (m *Model) regionTable(text string) (sheet.Rect, *sheet.Sheet, bool) {312+ const prefix = "nu."313+ if len(text) <= len(prefix) || !strings.EqualFold(text[:len(prefix)], prefix) {314+ return sheet.Rect{}, nil, false315+ }316+ s, reg, ok := m.book().Region(text[len(prefix):])317+ if !ok {318+ return sheet.Rect{}, nil, false319+ }320+ if t, ok := s.RegionTable(reg.Name); ok {321+ return t, s, true322+ }323+ return sheet.Rect{From: reg.At, To: reg.At}, s, true324+}