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
| M | docs/ | 2 | +- |
| M | e2e/ | 2 | +- |
| M | e2e/ | 2 | +- |
| A | internal/ | 42 | ++++++++++++++++++++++++++++++ |
| M | internal/ | 2 | +- |
| M | internal/ | 29 | ++++++++++++++++++--- |
@@ -22,7 +22,7 @@ mouse and the vim keymap added.
2222 | PgUp, PgDn | A screen up, down |2323 | Alt+PgUp, Alt+PgDn | A screen left, right |2424 | Home, Ctrl+Home, Ctrl+End | Column A, cell A1, the last used cell |25-| Ctrl+G, F5 | Go to a cell, a range or a named range, on any sheet (`Sheet2!B3`) |25+| Ctrl+G, F5 | Go to a cell, a range, a named range or a region's table (`nu.r1`), on any sheet (`Sheet2!B3`) |2626 2727 ## Entering data2828 @@ -102,7 +102,7 @@ var screens = []screen{
102102 }},103103 {name: "error-goto", setup: func(s *session) {104104 s.keys("<f5>", "nope", "<enter>")105- s.waitFor("Not a cell, range or named range")105+ s.waitFor("Not a cell, range, named range or region")106106 }},107107 {name: "help", setup: func(s *session) {108108 s.keys("<f1>")@@ -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@@ -0,0 +1,42 @@
1+package ui2+3+import (4+ "testing"5+6+ "github.com/FelineStateMachine/012/internal/sheet"7+)8+9+// Go to takes a region's name as formulas write it and selects its10+// table, header row included, on whichever sheet holds it.11+func TestGotoRegion(t *testing.T) {12+ m := newModel()13+ nb, err := m.book().AddNotebook("Shell", m.sheet)14+ if err != nil {15+ t.Fatal(err)16+ }17+ if err := nb.AddRegion(sheet.Region{Name: "totals", Command: "ls"}); err != nil {18+ t.Fatal(err)19+ }20+ d := &sheet.RegionData{Rows: 3, Cols: 2, Values: make([]sheet.Value, 6)}21+ for i := range d.Values {22+ d.Values[i] = sheet.Value{Kind: sheet.Text, Str: "x"}23+ }24+ if err := nb.ShowRegion("totals", d); err != nil {25+ t.Fatal(err)26+ }27+ want, ok := nb.RegionTable("totals")28+ if !ok {29+ t.Fatal("no table")30+ }31+ press(t, m, "<ctrl+g>", "NU.Totals", "<enter>")32+ if m.mode != modeReady || m.sheet != nb {33+ t.Fatalf("mode %v, sheet %q, err %q", m.mode, m.sheet.Name(), m.errMsg)34+ }35+ if got := m.selection(); got != want {36+ t.Errorf("selected %v, want the table %v", got, want)37+ }38+ press(t, m, "<f5>", "nu.nothing", "<enter>")39+ if m.mode != modeError {40+ t.Errorf("an unknown region: mode %v", m.mode)41+ }42+}@@ -126,7 +126,7 @@ func TestGotoAcceptsNamesAndRanges(t *testing.T) {
126126 t.Errorf("range: %v", m.selection())127127 }128128 press(t, m, "<f5>", "nope", "<enter>")129- if m.mode != modeError || m.errMsg != "Not a cell, range or named range: nope" {129+ if m.mode != modeError || m.errMsg != "Not a cell, range, named range or region: nope" {130130 t.Errorf("%v %q", m.mode, m.errMsg)131131 }132132 }@@ -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+}