(ctx context.Context, svc *docs.Service, docID string, target docsImageTarget)
| 408 | } |
| 409 | |
| 410 | func (c *DocsInsertImageCmd) resolveImageTarget(ctx context.Context, svc *docs.Service, docID string, target docsImageTarget) (int64, *docsedit.TextRange, string, error) { |
| 411 | if target.mode == docsImageAnchorReplace && strings.EqualFold(target.anchor, docsAtIndexEnd) { |
| 412 | endIndex, tabID, err := docsTargetEndIndexAndTabID(ctx, svc, docID, c.Tab) |
| 413 | if err != nil { |
| 414 | return 0, nil, "", err |
| 415 | } |
| 416 | return docsedit.AppendIndex(endIndex), nil, tabID, nil |
| 417 | } |
| 418 | loaded, err := loadDocsTargetDocument(ctx, svc, docID, c.Tab) |
| 419 | if err != nil { |
| 420 | return 0, nil, "", err |
| 421 | } |
| 422 | matches := docsedit.FindTextRanges(loaded.target, target.anchor, docsedit.SearchOptions{ |
| 423 | MatchCase: true, |
| 424 | PreserveHTMLEntities: true, |
| 425 | RequireTextSegment: true, |
| 426 | }) |
| 427 | if len(matches) == 0 { |
| 428 | return 0, nil, "", fmt.Errorf("anchor not found: %q", target.anchor) |
| 429 | } |
| 430 | match := matches[0] |
| 431 | switch target.mode { |
| 432 | case docsImageAnchorBefore: |
| 433 | return match.StartIndex, nil, loaded.tabID, nil |
| 434 | case docsImageAnchorAfter: |
| 435 | return match.EndIndex, nil, loaded.tabID, nil |
| 436 | default: |
| 437 | return match.StartIndex, &match, loaded.tabID, nil |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | func isDocsInsertImageMime(mimeType string) bool { |
| 442 | switch mimeType { |
no test coverage detected