MCPcopy Create free account
hub / github.com/openclaw/gogcli / resolveImageTarget

Method resolveImageTarget

internal/cmd/docs_insert_image.go:410–439  ·  view source on GitHub ↗
(ctx context.Context, svc *docs.Service, docID string, target docsImageTarget)

Source from the content-addressed store, hash-verified

408}
409
410func (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
441func isDocsInsertImageMime(mimeType string) bool {
442 switch mimeType {

Callers 2

buildInsertRequestsMethod · 0.95

Calls 5

AppendIndexFunction · 0.92
FindTextRangesFunction · 0.92
loadDocsTargetDocumentFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected