- commit
- 39d55680ed08256cb68a70de1a27471025bf932a
- parent
- 8bb32b978ff3017f762d490a2e3afa0354c8e026
- author
- Dami <dami.etoile@gmail.com>
- kind
- feat risk score 1.2 of 3, Jev's estimate
| M | docs/ | 2 | +- |
| M | e2e/ | 2 | +- |
| M | e2e/ | 2 | +- |
| M | internal/ | 10 | +++++++++- |
| M | internal/ | 2 | +- |
| M | internal/ | 9 | ++++++--- |
| M | internal/ | 7 | +++++++ |
@@ -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, a named range or a region's table (`nu.r1`), on any sheet (`Sheet2!B3`) |25+| Ctrl+G, F5 | Go to a cell, a range, a named range, a [table](../sheets/tables.md) or a region's table (`r1` or `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, named range or region")105+ s.waitFor("Not a cell, range, named range, table 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">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 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">table</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@@ -208,7 +208,7 @@ func (m *Model) editName(n sheet.Name, sel sheet.Rect) {
208208 }209209 210210 // namedSelection is the name of the selected range, if it has one, for211-// the name box, as in Sheets.211+// the name box, as in Sheets: a named range's, or a table's.212212 func (g *grid) namedSelection() (string, bool) {213213 r := g.selection()214214 for _, n := range g.sheet.Names() {@@ -216,5 +216,13 @@ func (g *grid) namedSelection() (string, bool) {
216216 return n.Name, true217217 }218218 }219+ if !g.sheet.HasTables() {220+ return "", false221+ }222+ for _, t := range g.sheet.Tables() {223+ if t.Range == r {224+ return t.Name, true225+ }226+ }219227 return "", false220228 }@@ -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, named range or region: nope" {129+ if m.mode != modeError || m.errMsg != "Not a cell, range, named range, table or region: nope" {130130 t.Errorf("%v %q", m.mode, m.errMsg)131131 }132132 }@@ -258,15 +258,15 @@ 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, named range or region: " + text)261+ m.fail("Not a cell, range, named range, table or region: " + text)262262 }263263 return nil264264 })265265 m.prompt.indicator = "POINT"266266 }267267 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 named268+// gotoText goes to a cell, range, named range, table (a region's too,269+// by its name or as formulas name it, nu.r1), on any sheet, and reports whether text named270270 // 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.sheet@@ -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 t, found := m.book().LookupTable(text); !ok && found && t.Shown() && target == m.sheet {290+ r, ok, target = t.Range, true, t.Sheet291+ }289292 if !ok && target == m.sheet {290293 r, target, ok = m.regionTable(text)291294 }@@ -37,6 +37,9 @@ func TestConvertToTable(t *testing.T) {
3737 if l := line(m, contextLine); !strings.Contains(l, "=SUM(Sales[Amount])") {3838 t.Errorf("note %q", l)3939 }40+ if l := line(m, formulaLine); !strings.HasPrefix(l, " Sales") {41+ t.Errorf("name box %q", l)42+ }4043 if m.available("table.create") {4144 t.Error("Convert to table offered inside a table")4245 }@@ -125,6 +128,10 @@ func TestTablesPicker(t *testing.T) {
125128 if m.selection() != rectOf("F1:G3") {126129 t.Errorf("went to %v", m.selection())127130 }131+ press(t, m, "<esc>", "<f5>", "sales", "<enter>")132+ if m.selection() != rectOf("A1:C4") {133+ t.Errorf("Go to a table: %v", m.selection())134+ }128135 m.runCommand("data.tables")129136 press(t, m, "sales", "<ctrl+d>")130137 if _, _, ok := m.book().Table("Sales"); ok {