Browse Source

Issue 1676: Don't eat up the last newline in a multi-line replacement (#1777)

cvzakharchenko 8 tháng trước cách đây
mục cha
commit
8db75266d0

+ 4 - 1
packages/opencode/src/tool/edit.ts

@@ -188,7 +188,10 @@ export const LineTrimmedReplacer: Replacer = function* (content, find) {
 
 
       let matchEndIndex = matchStartIndex
       let matchEndIndex = matchStartIndex
       for (let k = 0; k < searchLines.length; k++) {
       for (let k = 0; k < searchLines.length; k++) {
-        matchEndIndex += originalLines[i + k].length + 1
+        matchEndIndex += originalLines[i + k].length
+        if (k < searchLines.length - 1) {
+          matchEndIndex += 1 // Add newline character except for the last line
+        }
       }
       }
 
 
       yield content.substring(matchStartIndex, matchEndIndex)
       yield content.substring(matchStartIndex, matchEndIndex)