cat / 012
clone

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

Go to a row on a source's tab; keys of linked sources

Dami committed 0f199a6
commit
0f199a60157acab309ef4137f534657de6fffdfc
parent
9f59fd13428f87ffb12be79ac5a5400c8e173e38
author
Dami <dami.etoile@gmail.com>
kind
feat risk score 1.2 of 3, Jev's estimate
4 files changed, +48 -1
Mdocs/files/sources.md1+
Mdocs/reference/keys.md7++++++
Minternal/ui/sources_test.go6+++++
Minternal/ui/srccmds.go35+++++++++++++++++++++++++++++-
M docs/files/sources.md +1 -0
M docs/reference/keys.md +7 -0
M internal/ui/sources_test.go +6 -0
M internal/ui/srccmds.go +34 -1
@@ -4,6 +4,9 @@ import (
44 "fmt"55 "path/filepath"66 "slices"7+ "strconv"8+ "strings"9+ "unicode"710 811 tea "charm.land/bubbletea/v2"912
@@ -48,7 +51,7 @@ var sourceTakes = map[string]bool{
4851 "edit.copy": true, "data.sort_sheet_az": true, "data.sort_sheet_za": true, "data.sort_range_az": true,4952 "data.sort_range_za": true, "data.filter": true, "data.filter_column": true, "data.filter_remove": true,5053 "data.pivot": true, "data.frequency": true, "data.source_all": true, "data.source_reload": true,51- "data.link_source": true, "data.link": true,54+ "data.link_source": true, "data.link": true, "goto": true,5255 }5356 5457 // sourceCommand runs id on a source's tab, reporting whether it did:
@@ -87,6 +90,9 @@ func (m *Model) sourceCommand(c *command) (tea.Cmd, bool) {
8790 return m.setSourceOrder(info, o), true8891 case "data.pivot", "data.frequency":8992 return m.sourcePivot(info, col, c.id == "data.frequency"), true93+ case "goto":94+ m.openText("Go to a row, or a cell such as C5000000:", "", (*Model).sourceGoto)95+ return nil, true9096 }9197 return nil, false9298 }
@@ -238,3 +244,30 @@ func (m *Model) addSource(src sheet.LinkSource) {
238244 m.linkedHere(before)239245 m.note = "Linked " + filepath.Base(src.Path) + " as " + s.Name() + ": formulas read it as " + s.Name() + "[column]"240246 }247+248+// sourceGoto moves the active cell on a source's tab to where text249+// says: a row number, or a column's letters and a row number, as the250+// tab numbers its rows (the source's first row is 2).251+func (m *Model) sourceGoto(text string) tea.Cmd {252+ v := m.srcView()253+ if v == nil {254+ return nil255+ }256+ text = strings.ToUpper(strings.ReplaceAll(strings.TrimSpace(text), ",", ""))257+ letters := strings.TrimRightFunc(text, unicode.IsDigit)258+ row, err := strconv.ParseInt(text[len(letters):], 10, 64)259+ _, col := v.Active()260+ if letters != "" {261+ c, ok := sheet.ParseCol(letters)262+ if !ok {263+ err = strconv.ErrSyntax264+ }265+ col = c266+ }267+ if err != nil || row < 1 {268+ m.fail("Type a row, such as 5000000, or a cell, such as C5000000")269+ return nil270+ }271+ v.MoveTo(max(row-2, 0), col)272+ return nil273+}