(filePath string, change types.ChangeData, account *types.Account)
| 107 | } |
| 108 | |
| 109 | func applyEditorChange(filePath string, change types.ChangeData, account *types.Account) error { |
| 110 | content, err := os.ReadFile(filePath) |
| 111 | if err != nil { |
| 112 | return err |
| 113 | } |
| 114 | |
| 115 | lines := strings.Split(string(content), "\n") |
| 116 | |
| 117 | startLine := change.Range.StartLineNumber - 1 |
| 118 | startCol := change.Range.StartColumn - 1 |
| 119 | endLine := change.Range.EndLineNumber - 1 |
| 120 | endCol := change.Range.EndColumn - 1 |
| 121 | |
| 122 | startCol = adjustUTF8Position(lines, startLine, startCol) |
| 123 | endCol = adjustUTF8Position(lines, endLine, endCol) |
| 124 | |
| 125 | switch change.Type { |
| 126 | case "insert": |
| 127 | return applyInsert(filePath, lines, startLine, startCol, change.Text, account) |
| 128 | case "delete": |
| 129 | return applyDelete(filePath, lines, startLine, startCol, endLine, endCol, account) |
| 130 | case "replace": |
| 131 | return applyReplace(filePath, lines, startLine, startCol, endLine, endCol, change.Text, account) |
| 132 | default: |
| 133 | return nil |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | func adjustUTF8Position(lines []string, lineNum, col int) int { |
| 138 | if lineNum < 0 || lineNum >= len(lines) { |
no test coverage detected