Jelajahi Sumber

fix: keep empty lines when killing spaces

tophf 3 tahun lalu
induk
melakukan
be3c152d0d
1 mengubah file dengan 3 tambahan dan 1 penghapusan
  1. 3 1
      src/common/ui/code-trailing-spaces.js

+ 3 - 1
src/common/ui/code-trailing-spaces.js

@@ -7,12 +7,14 @@ const DEFAULTS = {
   [KILL_OPT]: true,
   [SHOW_OPT]: true,
 };
+/** Regexp's \s minus \r\n */
+const WS_RE = /[\u0020\f\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+$/gm;
 
 export const killTrailingSpaces = (cm, placeholders) => {
   const text = cm.getValue();
   const shouldKill = cm.options[KILL_OPT];
   const trimmed = shouldKill
-    ? text.replace(/\s+$/gm, '\n')
+    ? text.replace(WS_RE, '\n')
     : text;
   if (text !== trimmed) {
     cm.operation(() => {