(ctx context.Context, data wshrpc.CommandResolveIdsData, value string)
| 198 | } |
| 199 | |
| 200 | func resolveView(ctx context.Context, data wshrpc.CommandResolveIdsData, value string) (*waveobj.ORef, error) { |
| 201 | matches := viewBlockRe.FindStringSubmatch(value) |
| 202 | if matches == nil { |
| 203 | return nil, fmt.Errorf("invalid view format: %s", value) |
| 204 | } |
| 205 | |
| 206 | // Default to first instance if no number specified |
| 207 | viewType := matches[1] |
| 208 | instanceNum := 1 |
| 209 | if matches[2] != "" { |
| 210 | num, err := strconv.Atoi(matches[2]) |
| 211 | if err != nil { |
| 212 | return nil, fmt.Errorf("invalid view instance number: %v", err) |
| 213 | } |
| 214 | instanceNum = num |
| 215 | } |
| 216 | if instanceNum < 1 { |
| 217 | return nil, fmt.Errorf("invalid view instance number: %d", instanceNum) |
| 218 | } |
| 219 | // Get current tab |
| 220 | tabId, err := wstore.DBFindTabForBlockId(ctx, data.BlockId) |
| 221 | if err != nil { |
| 222 | return nil, fmt.Errorf("error finding tab: %v", err) |
| 223 | } |
| 224 | tab, err := wstore.DBMustGet[*waveobj.Tab](ctx, tabId) |
| 225 | if err != nil { |
| 226 | return nil, fmt.Errorf("error retrieving tab: %v", err) |
| 227 | } |
| 228 | layout, err := wstore.DBMustGet[*waveobj.LayoutState](ctx, tab.LayoutState) |
| 229 | if err != nil { |
| 230 | return nil, fmt.Errorf("error retrieving layout: %v", err) |
| 231 | } |
| 232 | if layout.LeafOrder == nil { |
| 233 | return nil, fmt.Errorf("no blocks in layout") |
| 234 | } |
| 235 | // Find nth instance of view type |
| 236 | count := 0 |
| 237 | for _, leaf := range *layout.LeafOrder { |
| 238 | leafBlockId := leaf.BlockId |
| 239 | leafBlock, err := wstore.DBMustGet[*waveobj.Block](ctx, leafBlockId) |
| 240 | if err != nil { |
| 241 | continue |
| 242 | } |
| 243 | if leafBlock.Meta.GetString("view", "") == viewType { |
| 244 | count++ |
| 245 | if count == instanceNum { |
| 246 | return &waveobj.ORef{OType: waveobj.OType_Block, OID: leaf.BlockId}, nil |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | return nil, fmt.Errorf("could not find block %d of type %s (found %d)", instanceNum, viewType, count) |
| 251 | } |
| 252 | |
| 253 | func resolveUUID(ctx context.Context, value string) (*waveobj.ORef, error) { |
| 254 | return wstore.DBResolveEasyOID(ctx, value) |
no test coverage detected