draftify-cli 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/repl.js +11 -2
- package/package.json +1 -1
package/dist/repl.js
CHANGED
|
@@ -666,14 +666,23 @@ async function startRepl(initialUsername) {
|
|
|
666
666
|
diffApplied = true;
|
|
667
667
|
}
|
|
668
668
|
else {
|
|
669
|
-
// Fallback: try stripping leading/trailing empty lines/whitespace from the search block
|
|
669
|
+
// Fallback 1: try stripping leading/trailing empty lines/whitespace from the search block
|
|
670
670
|
const trimmedSearch = search.trim();
|
|
671
671
|
if (trimmedSearch && normalizedFile.includes(trimmedSearch)) {
|
|
672
672
|
fileContent = normalizedFile.replace(trimmedSearch, replace.trim());
|
|
673
673
|
diffApplied = true;
|
|
674
674
|
}
|
|
675
675
|
else {
|
|
676
|
-
|
|
676
|
+
// Fallback 2: Regex fuzzy matching that ignores exact whitespace differences (e.g. indentation or newlines)
|
|
677
|
+
const escapedSearch = trimmedSearch.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\s+/g, '\\s+');
|
|
678
|
+
const regex = new RegExp(escapedSearch);
|
|
679
|
+
if (regex.test(normalizedFile)) {
|
|
680
|
+
fileContent = normalizedFile.replace(regex, replace.trim());
|
|
681
|
+
diffApplied = true;
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
ui_1.ui.error(`Could not apply diff to ${filePath}: SEARCH block not exactly matched.`);
|
|
685
|
+
}
|
|
677
686
|
}
|
|
678
687
|
}
|
|
679
688
|
}
|