Browse Source

fix(editor): wrong indent removal fn

Andelf 4 years ago
parent
commit
983c0bc16a
1 changed files with 5 additions and 7 deletions
  1. 5 7
      src/main/frontend/text.cljs

+ 5 - 7
src/main/frontend/text.cljs

@@ -350,10 +350,8 @@
 (defn remove-indentations
   [text]
   (when (string? text)
-    (let [lines (string/split-lines text)
-          spaces (re-find #"^[\s\t]+" (first lines))
-          spaces-count (count spaces)]
-      (string/join "\n" (map (fn [line]
-                               (let [spaces (re-find #"^[\s\t]+" line)
-                                     spaces-count (min (count spaces) spaces-count)]
-                                 (util/safe-subs line spaces-count))) lines)))))
+    (let [lines (string/split text #"\r?\n" -1)
+          spaces-count (apply min (map #(count (re-find #"^[\s\t]+" %)) lines))]
+      (if (zero? spaces-count)
+        text
+        (string/join "\n" (map #(util/safe-subs % spaces-count) lines))))))