(ctx context.Context, svc *docs.Service, docID string)
| 219 | } |
| 220 | |
| 221 | func (c *DocsFormatCmd) targetRanges(ctx context.Context, svc *docs.Service, docID string) ([]docsFormatTargetRange, docsRequestTarget, error) { |
| 222 | loaded, err := loadDocsTargetSegment(ctx, svc, docID, c.Tab, c.Segment) |
| 223 | if err != nil { |
| 224 | return nil, docsRequestTarget{}, err |
| 225 | } |
| 226 | targetDoc := loaded.target |
| 227 | target := docsRequestTarget{TabID: loaded.tabID, SegmentID: loaded.segmentID, SegmentKind: loaded.segmentKind} |
| 228 | |
| 229 | var ranges []docsedit.TextRange |
| 230 | if strings.TrimSpace(c.Match) == "" { |
| 231 | start := int64(1) |
| 232 | if target.SegmentID != "" { |
| 233 | start = 0 |
| 234 | } |
| 235 | end := docsDocumentEndIndex(targetDoc) - 1 |
| 236 | if end > start { |
| 237 | ranges = []docsedit.TextRange{{StartIndex: start, EndIndex: end}} |
| 238 | } |
| 239 | } else { |
| 240 | ranges = docsedit.FindTextRanges(targetDoc, c.Match, docsedit.SearchOptions{ |
| 241 | MatchCase: c.MatchCase, |
| 242 | PreserveHTMLEntities: true, |
| 243 | RequireTextSegment: true, |
| 244 | }) |
| 245 | if !c.MatchAll && len(ranges) > 1 { |
| 246 | ranges = ranges[:1] |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | paragraphs := []docssed.DocumentParagraph(nil) |
| 251 | if projection := docssed.ProjectDocument(targetDoc); projection.Legacy != nil { |
| 252 | paragraphs = projection.Legacy.Paragraphs |
| 253 | } |
| 254 | targets := make([]docsFormatTargetRange, 0, len(ranges)) |
| 255 | for _, r := range ranges { |
| 256 | target := docsFormatTargetRange{TextRange: r} |
| 257 | if c.Format.createsBullets() { |
| 258 | target.BulletParagraphs = docsFormatBulletParagraphs(paragraphs, r.StartIndex, r.EndIndex) |
| 259 | } |
| 260 | targets = append(targets, target) |
| 261 | } |
| 262 | return targets, target, nil |
| 263 | } |
| 264 | |
| 265 | type docsFormatTargetRange struct { |
| 266 | docsedit.TextRange |
no test coverage detected