(filePath string, lines []string, startLine, startCol, endLine, endCol int, account *types.Account)
| 173 | } |
| 174 | |
| 175 | func applyDelete(filePath string, lines []string, startLine, startCol, endLine, endCol int, account *types.Account) error { |
| 176 | if startLine < 0 || startLine >= len(lines) || endLine < 0 || endLine >= len(lines) { |
| 177 | return fmt.Errorf("line numbers out of range: %d-%d", startLine, endLine) |
| 178 | } |
| 179 | |
| 180 | if startLine == endLine { |
| 181 | line := lines[startLine] |
| 182 | runes := []rune(line) |
| 183 | |
| 184 | startCol = utils.Clamp(startCol, 0, len(runes)) |
| 185 | endCol = utils.Clamp(endCol, 0, len(runes)) |
| 186 | |
| 187 | if startCol >= endCol { |
| 188 | return nil |
| 189 | } |
| 190 | |
| 191 | newRunes := make([]rune, 0, len(runes)-(endCol-startCol)) |
| 192 | newRunes = append(newRunes, runes[:startCol]...) |
| 193 | newRunes = append(newRunes, runes[endCol:]...) |
| 194 | lines[startLine] = string(newRunes) |
| 195 | |
| 196 | } else { |
| 197 | firstLineRunes := []rune(lines[startLine]) |
| 198 | lastLineRunes := []rune(lines[endLine]) |
| 199 | |
| 200 | startCol = utils.Clamp(startCol, 0, len(firstLineRunes)) |
| 201 | endCol = utils.Clamp(endCol, 0, len(lastLineRunes)) |
| 202 | |
| 203 | newFirstLine := string(firstLineRunes[:startCol]) |
| 204 | |
| 205 | newLastLine := string(lastLineRunes[endCol:]) |
| 206 | |
| 207 | lines[startLine] = newFirstLine + newLastLine |
| 208 | |
| 209 | if startLine < endLine { |
| 210 | lines = append(lines[:startLine+1], lines[endLine+1:]...) |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | return writeFile(filePath, lines, account) |
| 215 | } |
| 216 | |
| 217 | func applyReplace(filePath string, lines []string, startLine, startCol, endLine, endCol int, text string, account *types.Account) error { |
| 218 | if startLine == endLine { |
no test coverage detected