MCPcopy Create free account
hub / github.com/MertJSX/folderhost / applyInsert

Function applyInsert

middleware/websocket/file_editor.go:151–173  ·  view source on GitHub ↗
(filePath string, lines []string, lineNum, col int, text string, account *types.Account)

Source from the content-addressed store, hash-verified

149}
150
151func applyInsert(filePath string, lines []string, lineNum, col int, text string, account *types.Account) error {
152 if lineNum < 0 || lineNum >= len(lines) {
153 return fmt.Errorf("line number out of range: %d", lineNum)
154 }
155
156 line := lines[lineNum]
157 runes := []rune(line)
158
159 if col < 0 {
160 col = 0
161 }
162 if col > len(runes) {
163 col = len(runes)
164 }
165
166 newRunes := make([]rune, 0, len(runes)+len([]rune(text)))
167 newRunes = append(newRunes, runes[:col]...)
168 newRunes = append(newRunes, []rune(text)...)
169 newRunes = append(newRunes, runes[col:]...)
170
171 lines[lineNum] = string(newRunes)
172 return writeFile(filePath, lines, account)
173}
174
175func 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) {

Callers 1

applyEditorChangeFunction · 0.85

Calls 1

writeFileFunction · 0.85

Tested by

no test coverage detected