getNextTabName returns the next auto-generated tab name (e.g. "T3") given a slice of existing tab names. It filters to names matching T[N] where N is a positive integer, finds the maximum N, and returns T[max+1]. If no matching names exist it returns "T1".
(tabNames []string)
| 202 | // positive integer, finds the maximum N, and returns T[max+1]. If no matching |
| 203 | // names exist it returns "T1". |
| 204 | func getNextTabName(tabNames []string) string { |
| 205 | maxNum := 0 |
| 206 | for _, name := range tabNames { |
| 207 | m := tabNameRe.FindStringSubmatch(name) |
| 208 | if m == nil { |
| 209 | continue |
| 210 | } |
| 211 | n, err := strconv.Atoi(m[1]) |
| 212 | if err != nil || n <= 0 { |
| 213 | continue |
| 214 | } |
| 215 | if n > maxNum { |
| 216 | maxNum = n |
| 217 | } |
| 218 | } |
| 219 | return "T" + strconv.Itoa(maxNum+1) |
| 220 | } |
| 221 | |
| 222 | // returns tabid |
| 223 | func CreateTab(ctx context.Context, workspaceId string, tabName string, activateTab bool, isInitialLaunch bool) (string, error) { |