tuanchris 5 месяцев назад
Родитель
Сommit
96f5a384c6
3 измененных файлов с 26 добавлено и 3 удалено
  1. 4 1
      main.py
  2. 11 1
      static/js/base.js
  3. 11 1
      static/js/index.js

+ 4 - 1
main.py

@@ -44,10 +44,13 @@ logger = logging.getLogger(__name__)
 
 def normalize_file_path(file_path: str) -> str:
     """Normalize file path separators for consistent cross-platform handling."""
+    if not file_path:
+        return ''
+    
     # First normalize path separators
     normalized = file_path.replace('\\', '/')
     
-    # Remove any patterns directory prefixes that might be present
+    # Remove only the patterns directory prefix from the beginning, not patterns within the path
     if normalized.startswith('./patterns/'):
         normalized = normalized[11:]
     elif normalized.startswith('patterns/'):

+ 11 - 1
static/js/base.js

@@ -3,7 +3,17 @@
 // Helper function to normalize file paths for cross-platform compatibility
 function normalizeFilePath(filePath) {
     if (!filePath) return '';
-    return filePath.replace('./patterns\\', '').replace('./patterns/', '').replace('patterns\\', '').replace('patterns/', '');
+    // First normalize path separators
+    let normalized = filePath.replace(/\\/g, '/');
+    
+    // Remove only the patterns directory prefix, not patterns within the path
+    if (normalized.startsWith('./patterns/')) {
+        normalized = normalized.substring(11);
+    } else if (normalized.startsWith('patterns/')) {
+        normalized = normalized.substring(9);
+    }
+    
+    return normalized;
 }
 
 let ws = null;

+ 11 - 1
static/js/index.js

@@ -4,7 +4,17 @@ let allPatterns = [];
 // Helper function to normalize file paths for cross-platform compatibility
 function normalizeFilePath(filePath) {
     if (!filePath) return '';
-    return filePath.replace('./patterns\\', '').replace('./patterns/', '').replace('patterns\\', '').replace('patterns/', '');
+    // First normalize path separators
+    let normalized = filePath.replace(/\\/g, '/');
+    
+    // Remove only the patterns directory prefix, not patterns within the path
+    if (normalized.startsWith('./patterns/')) {
+        normalized = normalized.substring(11);
+    } else if (normalized.startsWith('patterns/')) {
+        normalized = normalized.substring(9);
+    }
+    
+    return normalized;
 }
 let selectedPattern = null;
 let previewObserver = null;