| 32 | } |
| 33 | |
| 34 | func BuildWriteRequests(options WriteOptions) ([]*docs.Request, error) { |
| 35 | requests := make([]*docs.Request, 0, 3) |
| 36 | |
| 37 | if !options.Append { |
| 38 | deleteEnd := options.EndIndex - 1 |
| 39 | if deleteEnd > 1 { |
| 40 | requests = append(requests, BuildDeleteRequest(Range{Start: 1, End: deleteEnd}, options.TabID)) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | requests = append(requests, BuildInsertRequest(options.Text, options.InsertIndex, options.TabID)) |
| 45 | if options.Format.Any() { |
| 46 | format := options.Format |
| 47 | if !options.Append && createsParagraphBullets(format) && hasParagraphStyle(format) { |
| 48 | format.PostBulletParagraphStart = options.InsertIndex |
| 49 | format.PostBulletParagraphEnd = options.InsertIndex + utf16Length(options.Text) - leadingParagraphTabs(options.Text) |
| 50 | } |
| 51 | |
| 52 | formatRequests, err := docsformat.BuildRequests( |
| 53 | format, |
| 54 | options.InsertIndex, |
| 55 | options.InsertIndex+utf16Length(options.Text), |
| 56 | options.TabID, |
| 57 | ) |
| 58 | if err != nil { |
| 59 | return nil, fmt.Errorf("build format requests: %w", err) |
| 60 | } |
| 61 | |
| 62 | requests = append(requests, formatRequests...) |
| 63 | } |
| 64 | |
| 65 | return requests, nil |
| 66 | } |
| 67 | |
| 68 | func createsParagraphBullets(options docsformat.Options) bool { |
| 69 | return options.Bullets || options.Ordered || strings.TrimSpace(options.BulletPreset) != "" |