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

Function applyEditorChange

middleware/websocket/file_editor.go:109–135  ·  view source on GitHub ↗
(filePath string, change types.ChangeData, account *types.Account)

Source from the content-addressed store, hash-verified

107}
108
109func 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
137func adjustUTF8Position(lines []string, lineNum, col int) int {
138 if lineNum < 0 || lineNum >= len(lines) {

Callers 1

processWebSocketMessageFunction · 0.85

Calls 4

adjustUTF8PositionFunction · 0.85
applyInsertFunction · 0.85
applyDeleteFunction · 0.85
applyReplaceFunction · 0.85

Tested by

no test coverage detected