Przeglądaj źródła

Add updateLib.js

Gerald 10 lat temu
rodzic
commit
02b97a033f

+ 10 - 1
package.json

@@ -1,9 +1,13 @@
 {
 {
   "name": "Violentmonkey",
   "name": "Violentmonkey",
   "version": "2.2.0",
   "version": "2.2.0",
+  "scripts": {
+    "update": "node scripts/updateLib"
+  },
   "description": "Violentmonkey",
   "description": "Violentmonkey",
   "devDependencies": {
   "devDependencies": {
     "del": "^2.1.0",
     "del": "^2.1.0",
+    "glob": "^6.0.1",
     "gulp": "^3.9.0",
     "gulp": "^3.9.0",
     "gulp-concat": "^2.6.0",
     "gulp-concat": "^2.6.0",
     "gulp-filter": "^3.0.1",
     "gulp-filter": "^3.0.1",
@@ -11,6 +15,7 @@
     "gulp-util": "^3.0.7",
     "gulp-util": "^3.0.7",
     "html-minifier": "^1.0.0",
     "html-minifier": "^1.0.0",
     "merge2": "^0.3.6",
     "merge2": "^0.3.6",
+    "ncp": "^2.0.0",
     "through2": "^2.0.0",
     "through2": "^2.0.0",
     "underscore": "^1.8.3"
     "underscore": "^1.8.3"
   },
   },
@@ -23,5 +28,9 @@
     "url": "https://github.com/Violentmonkey/Violentmonkey/issues"
     "url": "https://github.com/Violentmonkey/Violentmonkey/issues"
   },
   },
   "homepage": "https://github.com/Violentmonkey/Violentmonkey",
   "homepage": "https://github.com/Violentmonkey/Violentmonkey",
-  "license": "MIT"
+  "license": "MIT",
+  "dependencies": {
+    "codemirror": "^5.9.0",
+    "font-awesome": "^4.5.0"
+  }
 }
 }

+ 62 - 0
scripts/updateLib.js

@@ -0,0 +1,62 @@
+'use strict';
+
+const fs = require('fs');
+const path = require('path');
+const glob = require('glob');
+const ncp = require('ncp');
+
+const aliases = {
+  CodeMirror: 'codemirror',
+  'font-awesome': {},
+};
+
+function getFiles(pattern, cwd) {
+  return new Promise((resolve, reject) => {
+    glob(pattern, {nodir: true, cwd: cwd || '.'}, (err, files) => {
+      err ? reject(err) : resolve(files);
+    });
+  });
+}
+
+function readdir(dir) {
+  return new Promise((resolve, reject) => {
+    fs.readdir(dir, (err, files) => {
+      err ? reject(err) : resolve(files);
+    });
+  });
+}
+
+function copyFile(src, dest) {
+  return new Promise((resolve, reject) => {
+    ncp(src, dest, (err) => err ? reject(err) : resolve());
+  }).then(() => {
+    console.log(src + ' => ' + dest);
+  });
+}
+
+function update(lib, files) {
+  let alias = aliases[lib];
+  if (typeof alias === 'string') alias = {
+    lib: alias,
+  };
+  alias.lib = alias.lib || lib;
+  const libdir = `node_modules/${alias.lib}`;
+  const srcdir = `src/lib/${lib}`
+  return Promise.all(files.map((file) => {
+    let aliasFile = alias.files && alias.files[file] || file;
+    if (aliasFile.endsWith('/')) aliasFile += file;
+    const libfile = path.join(libdir, aliasFile);
+    return copyFile(libfile, path.join(srcdir, file));
+  })).catch(function (err) {
+    console.log(err);
+  });
+}
+
+readdir('./src/lib').then((data) => {
+  data.forEach(function (name) {
+    if (!aliases[name]) return;
+    getFiles('**', `src/lib/${name}`).then((files) => {
+      update(name, files);
+    });
+  });
+});

+ 155 - 119
src/lib/CodeMirror/addon/edit/closebrackets.js

@@ -9,27 +9,168 @@
   else // Plain browser env
   else // Plain browser env
     mod(CodeMirror);
     mod(CodeMirror);
 })(function(CodeMirror) {
 })(function(CodeMirror) {
-  var DEFAULT_BRACKETS = "()[]{}''\"\"";
-  var DEFAULT_EXPLODE_ON_ENTER = "[]{}";
-  var SPACE_CHAR_REGEX = /\s/;
+  var defaults = {
+    pairs: "()[]{}''\"\"",
+    triples: "",
+    explode: "[]{}"
+  };
 
 
   var Pos = CodeMirror.Pos;
   var Pos = CodeMirror.Pos;
 
 
   CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
   CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
-    if (old != CodeMirror.Init && old)
-      cm.removeKeyMap("autoCloseBrackets");
-    if (!val) return;
-    var pairs = DEFAULT_BRACKETS, explode = DEFAULT_EXPLODE_ON_ENTER;
-    if (typeof val == "string") pairs = val;
-    else if (typeof val == "object") {
-      if (val.pairs != null) pairs = val.pairs;
-      if (val.explode != null) explode = val.explode;
+    if (old && old != CodeMirror.Init) {
+      cm.removeKeyMap(keyMap);
+      cm.state.closeBrackets = null;
+    }
+    if (val) {
+      cm.state.closeBrackets = val;
+      cm.addKeyMap(keyMap);
     }
     }
-    var map = buildKeymap(pairs);
-    if (explode) map.Enter = buildExplodeHandler(explode);
-    cm.addKeyMap(map);
   });
   });
 
 
+  function getOption(conf, name) {
+    if (name == "pairs" && typeof conf == "string") return conf;
+    if (typeof conf == "object" && conf[name] != null) return conf[name];
+    return defaults[name];
+  }
+
+  var bind = defaults.pairs + "`";
+  var keyMap = {Backspace: handleBackspace, Enter: handleEnter};
+  for (var i = 0; i < bind.length; i++)
+    keyMap["'" + bind.charAt(i) + "'"] = handler(bind.charAt(i));
+
+  function handler(ch) {
+    return function(cm) { return handleChar(cm, ch); };
+  }
+
+  function getConfig(cm) {
+    var deflt = cm.state.closeBrackets;
+    if (!deflt) return null;
+    var mode = cm.getModeAt(cm.getCursor());
+    return mode.closeBrackets || deflt;
+  }
+
+  function handleBackspace(cm) {
+    var conf = getConfig(cm);
+    if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
+
+    var pairs = getOption(conf, "pairs");
+    var ranges = cm.listSelections();
+    for (var i = 0; i < ranges.length; i++) {
+      if (!ranges[i].empty()) return CodeMirror.Pass;
+      var around = charsAround(cm, ranges[i].head);
+      if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
+    }
+    for (var i = ranges.length - 1; i >= 0; i--) {
+      var cur = ranges[i].head;
+      cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1));
+    }
+  }
+
+  function handleEnter(cm) {
+    var conf = getConfig(cm);
+    var explode = conf && getOption(conf, "explode");
+    if (!explode || cm.getOption("disableInput")) return CodeMirror.Pass;
+
+    var ranges = cm.listSelections();
+    for (var i = 0; i < ranges.length; i++) {
+      if (!ranges[i].empty()) return CodeMirror.Pass;
+      var around = charsAround(cm, ranges[i].head);
+      if (!around || explode.indexOf(around) % 2 != 0) return CodeMirror.Pass;
+    }
+    cm.operation(function() {
+      cm.replaceSelection("\n\n", null);
+      cm.execCommand("goCharLeft");
+      ranges = cm.listSelections();
+      for (var i = 0; i < ranges.length; i++) {
+        var line = ranges[i].head.line;
+        cm.indentLine(line, null, true);
+        cm.indentLine(line + 1, null, true);
+      }
+    });
+  }
+
+  function contractSelection(sel) {
+    var inverted = CodeMirror.cmpPos(sel.anchor, sel.head) > 0;
+    return {anchor: new Pos(sel.anchor.line, sel.anchor.ch + (inverted ? -1 : 1)),
+            head: new Pos(sel.head.line, sel.head.ch + (inverted ? 1 : -1))};
+  }
+
+  function handleChar(cm, ch) {
+    var conf = getConfig(cm);
+    if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
+
+    var pairs = getOption(conf, "pairs");
+    var pos = pairs.indexOf(ch);
+    if (pos == -1) return CodeMirror.Pass;
+    var triples = getOption(conf, "triples");
+
+    var identical = pairs.charAt(pos + 1) == ch;
+    var ranges = cm.listSelections();
+    var opening = pos % 2 == 0;
+
+    var type, next;
+    for (var i = 0; i < ranges.length; i++) {
+      var range = ranges[i], cur = range.head, curType;
+      var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
+      if (opening && !range.empty()) {
+        curType = "surround";
+      } else if ((identical || !opening) && next == ch) {
+        if (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == ch + ch + ch)
+          curType = "skipThree";
+        else
+          curType = "skip";
+      } else if (identical && cur.ch > 1 && triples.indexOf(ch) >= 0 &&
+                 cm.getRange(Pos(cur.line, cur.ch - 2), cur) == ch + ch &&
+                 (cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != ch)) {
+        curType = "addFour";
+      } else if (identical) {
+        if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, ch)) curType = "both";
+        else return CodeMirror.Pass;
+      } else if (opening && (cm.getLine(cur.line).length == cur.ch ||
+                             isClosingBracket(next, pairs) ||
+                             /\s/.test(next))) {
+        curType = "both";
+      } else {
+        return CodeMirror.Pass;
+      }
+      if (!type) type = curType;
+      else if (type != curType) return CodeMirror.Pass;
+    }
+
+    var left = pos % 2 ? pairs.charAt(pos - 1) : ch;
+    var right = pos % 2 ? ch : pairs.charAt(pos + 1);
+    cm.operation(function() {
+      if (type == "skip") {
+        cm.execCommand("goCharRight");
+      } else if (type == "skipThree") {
+        for (var i = 0; i < 3; i++)
+          cm.execCommand("goCharRight");
+      } else if (type == "surround") {
+        var sels = cm.getSelections();
+        for (var i = 0; i < sels.length; i++)
+          sels[i] = left + sels[i] + right;
+        cm.replaceSelections(sels, "around");
+        sels = cm.listSelections().slice();
+        for (var i = 0; i < sels.length; i++)
+          sels[i] = contractSelection(sels[i]);
+        cm.setSelections(sels);
+      } else if (type == "both") {
+        cm.replaceSelection(left + right, null);
+        cm.triggerElectric(left + right);
+        cm.execCommand("goCharLeft");
+      } else if (type == "addFour") {
+        cm.replaceSelection(left + left + left + left, "before");
+        cm.execCommand("goCharRight");
+      }
+    });
+  }
+
+  function isClosingBracket(ch, pairs) {
+    var pos = pairs.lastIndexOf(ch);
+    return pos > -1 && pos % 2 == 1;
+  }
+
   function charsAround(cm, pos) {
   function charsAround(cm, pos) {
     var str = cm.getRange(Pos(pos.line, pos.ch - 1),
     var str = cm.getRange(Pos(pos.line, pos.ch - 1),
                           Pos(pos.line, pos.ch + 1));
                           Pos(pos.line, pos.ch + 1));
@@ -51,109 +192,4 @@
       stream.start = stream.pos;
       stream.start = stream.pos;
     }
     }
   }
   }
-
-  function buildKeymap(pairs) {
-    var map = {
-      name : "autoCloseBrackets",
-      Backspace: function(cm) {
-        if (cm.getOption("disableInput")) return CodeMirror.Pass;
-        var ranges = cm.listSelections();
-        for (var i = 0; i < ranges.length; i++) {
-          if (!ranges[i].empty()) return CodeMirror.Pass;
-          var around = charsAround(cm, ranges[i].head);
-          if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
-        }
-        for (var i = ranges.length - 1; i >= 0; i--) {
-          var cur = ranges[i].head;
-          cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1));
-        }
-      }
-    };
-    var closingBrackets = "";
-    for (var i = 0; i < pairs.length; i += 2) (function(left, right) {
-      closingBrackets += right;
-      map["'" + left + "'"] = function(cm) {
-        if (cm.getOption("disableInput")) return CodeMirror.Pass;
-        var ranges = cm.listSelections(), type, next;
-        for (var i = 0; i < ranges.length; i++) {
-          var range = ranges[i], cur = range.head, curType;
-          var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
-          if (!range.empty()) {
-            curType = "surround";
-          } else if (left == right && next == right) {
-            if (cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == left + left + left)
-              curType = "skipThree";
-            else
-              curType = "skip";
-          } else if (left == right && cur.ch > 1 &&
-                     cm.getRange(Pos(cur.line, cur.ch - 2), cur) == left + left &&
-                     (cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != left)) {
-            curType = "addFour";
-          } else if (left == '"' || left == "'") {
-            if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, left)) curType = "both";
-            else return CodeMirror.Pass;
-          } else if (cm.getLine(cur.line).length == cur.ch || closingBrackets.indexOf(next) >= 0 || SPACE_CHAR_REGEX.test(next)) {
-            curType = "both";
-          } else {
-            return CodeMirror.Pass;
-          }
-          if (!type) type = curType;
-          else if (type != curType) return CodeMirror.Pass;
-        }
-
-        cm.operation(function() {
-          if (type == "skip") {
-            cm.execCommand("goCharRight");
-          } else if (type == "skipThree") {
-            for (var i = 0; i < 3; i++)
-              cm.execCommand("goCharRight");
-          } else if (type == "surround") {
-            var sels = cm.getSelections();
-            for (var i = 0; i < sels.length; i++)
-              sels[i] = left + sels[i] + right;
-            cm.replaceSelections(sels, "around");
-          } else if (type == "both") {
-            cm.replaceSelection(left + right, null);
-            cm.execCommand("goCharLeft");
-          } else if (type == "addFour") {
-            cm.replaceSelection(left + left + left + left, "before");
-            cm.execCommand("goCharRight");
-          }
-        });
-      };
-      if (left != right) map["'" + right + "'"] = function(cm) {
-        var ranges = cm.listSelections();
-        for (var i = 0; i < ranges.length; i++) {
-          var range = ranges[i];
-          if (!range.empty() ||
-              cm.getRange(range.head, Pos(range.head.line, range.head.ch + 1)) != right)
-            return CodeMirror.Pass;
-        }
-        cm.execCommand("goCharRight");
-      };
-    })(pairs.charAt(i), pairs.charAt(i + 1));
-    return map;
-  }
-
-  function buildExplodeHandler(pairs) {
-    return function(cm) {
-      if (cm.getOption("disableInput")) return CodeMirror.Pass;
-      var ranges = cm.listSelections();
-      for (var i = 0; i < ranges.length; i++) {
-        if (!ranges[i].empty()) return CodeMirror.Pass;
-        var around = charsAround(cm, ranges[i].head);
-        if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
-      }
-      cm.operation(function() {
-        cm.replaceSelection("\n\n", null);
-        cm.execCommand("goCharLeft");
-        ranges = cm.listSelections();
-        for (var i = 0; i < ranges.length; i++) {
-          var line = ranges[i].head.line;
-          cm.indentLine(line, null, true);
-          cm.indentLine(line + 1, null, true);
-        }
-      });
-    };
-  }
 });
 });

+ 1 - 1
src/lib/CodeMirror/addon/edit/matchbrackets.js

@@ -81,7 +81,7 @@
     if (marks.length) {
     if (marks.length) {
       // Kludge to work around the IE bug from issue #1193, where text
       // Kludge to work around the IE bug from issue #1193, where text
       // input stops going to the textare whever this fires.
       // input stops going to the textare whever this fires.
-      if (ie_lt8 && cm.state.focused) cm.display.input.focus();
+      if (ie_lt8 && cm.state.focused) cm.focus();
 
 
       var clear = function() {
       var clear = function() {
         cm.operation(function() {
         cm.operation(function() {

+ 3 - 1
src/lib/CodeMirror/addon/fold/comment-fold.js

@@ -28,7 +28,9 @@ CodeMirror.registerGlobalHelper("fold", "comment", function(mode) {
       continue;
       continue;
     }
     }
     if (pass == 1 && found < start.ch) return;
     if (pass == 1 && found < start.ch) return;
-    if (/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1)))) {
+    if (/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1))) &&
+        (lineText.slice(found - endToken.length, found) == endToken ||
+         !/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found))))) {
       startCh = found + startToken.length;
       startCh = found + startToken.length;
       break;
       break;
     }
     }

+ 4 - 0
src/lib/CodeMirror/addon/fold/foldcode.js

@@ -142,4 +142,8 @@
       return editorOptions[name];
       return editorOptions[name];
     return defaultOptions[name];
     return defaultOptions[name];
   }
   }
+
+  CodeMirror.defineExtension("foldOption", function(options, name) {
+    return getOption(this, options, name);
+  });
 });
 });

+ 20 - 8
src/lib/CodeMirror/addon/fold/foldgutter.js

@@ -52,7 +52,7 @@
   function isFolded(cm, line) {
   function isFolded(cm, line) {
     var marks = cm.findMarksAt(Pos(line));
     var marks = cm.findMarksAt(Pos(line));
     for (var i = 0; i < marks.length; ++i)
     for (var i = 0; i < marks.length; ++i)
-      if (marks[i].__isFold && marks[i].find().from.line == line) return true;
+      if (marks[i].__isFold && marks[i].find().from.line == line) return marks[i];
   }
   }
 
 
   function marker(spec) {
   function marker(spec) {
@@ -67,14 +67,16 @@
 
 
   function updateFoldInfo(cm, from, to) {
   function updateFoldInfo(cm, from, to) {
     var opts = cm.state.foldGutter.options, cur = from;
     var opts = cm.state.foldGutter.options, cur = from;
+    var minSize = cm.foldOption(opts, "minFoldSize");
+    var func = cm.foldOption(opts, "rangeFinder");
     cm.eachLine(from, to, function(line) {
     cm.eachLine(from, to, function(line) {
       var mark = null;
       var mark = null;
       if (isFolded(cm, cur)) {
       if (isFolded(cm, cur)) {
         mark = marker(opts.indicatorFolded);
         mark = marker(opts.indicatorFolded);
       } else {
       } else {
-        var pos = Pos(cur, 0), func = opts.rangeFinder || CodeMirror.fold.auto;
+        var pos = Pos(cur, 0);
         var range = func && func(cm, pos);
         var range = func && func(cm, pos);
-        if (range && range.from.line + 1 < range.to.line)
+        if (range && range.to.line - range.from.line >= minSize)
           mark = marker(opts.indicatorOpen);
           mark = marker(opts.indicatorOpen);
       }
       }
       cm.setGutterMarker(line, opts.gutter, mark);
       cm.setGutterMarker(line, opts.gutter, mark);
@@ -92,20 +94,28 @@
   }
   }
 
 
   function onGutterClick(cm, line, gutter) {
   function onGutterClick(cm, line, gutter) {
-    var opts = cm.state.foldGutter.options;
+    var state = cm.state.foldGutter;
+    if (!state) return;
+    var opts = state.options;
     if (gutter != opts.gutter) return;
     if (gutter != opts.gutter) return;
-    cm.foldCode(Pos(line, 0), opts.rangeFinder);
+    var folded = isFolded(cm, line);
+    if (folded) folded.clear();
+    else cm.foldCode(Pos(line, 0), opts.rangeFinder);
   }
   }
 
 
   function onChange(cm) {
   function onChange(cm) {
-    var state = cm.state.foldGutter, opts = cm.state.foldGutter.options;
+    var state = cm.state.foldGutter;
+    if (!state) return;
+    var opts = state.options;
     state.from = state.to = 0;
     state.from = state.to = 0;
     clearTimeout(state.changeUpdate);
     clearTimeout(state.changeUpdate);
     state.changeUpdate = setTimeout(function() { updateInViewport(cm); }, opts.foldOnChangeTimeSpan || 600);
     state.changeUpdate = setTimeout(function() { updateInViewport(cm); }, opts.foldOnChangeTimeSpan || 600);
   }
   }
 
 
   function onViewportChange(cm) {
   function onViewportChange(cm) {
-    var state = cm.state.foldGutter, opts = cm.state.foldGutter.options;
+    var state = cm.state.foldGutter;
+    if (!state) return;
+    var opts = state.options;
     clearTimeout(state.changeUpdate);
     clearTimeout(state.changeUpdate);
     state.changeUpdate = setTimeout(function() {
     state.changeUpdate = setTimeout(function() {
       var vp = cm.getViewport();
       var vp = cm.getViewport();
@@ -127,7 +137,9 @@
   }
   }
 
 
   function onFold(cm, from) {
   function onFold(cm, from) {
-    var state = cm.state.foldGutter, line = from.line;
+    var state = cm.state.foldGutter;
+    if (!state) return;
+    var line = from.line;
     if (line >= state.from && line < state.to)
     if (line >= state.from && line < state.to)
       updateFoldInfo(cm, line, line + 1);
       updateFoldInfo(cm, line, line + 1);
   }
   }

+ 228 - 0
src/lib/CodeMirror/addon/search/search.js

@@ -0,0 +1,228 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+// Define search commands. Depends on dialog.js or another
+// implementation of the openDialog method.
+
+// Replace works a little oddly -- it will do the replace on the next
+// Ctrl-G (or whatever is bound to findNext) press. You prevent a
+// replace by making sure the match is no longer selected when hitting
+// Ctrl-G.
+
+(function(mod) {
+  if (typeof exports == "object" && typeof module == "object") // CommonJS
+    mod(require("../../lib/codemirror"), require("./searchcursor"), require("../dialog/dialog"));
+  else if (typeof define == "function" && define.amd) // AMD
+    define(["../../lib/codemirror", "./searchcursor", "../dialog/dialog"], mod);
+  else // Plain browser env
+    mod(CodeMirror);
+})(function(CodeMirror) {
+  "use strict";
+
+  function searchOverlay(query, caseInsensitive) {
+    if (typeof query == "string")
+      query = new RegExp(query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), caseInsensitive ? "gi" : "g");
+    else if (!query.global)
+      query = new RegExp(query.source, query.ignoreCase ? "gi" : "g");
+
+    return {token: function(stream) {
+      query.lastIndex = stream.pos;
+      var match = query.exec(stream.string);
+      if (match && match.index == stream.pos) {
+        stream.pos += match[0].length || 1;
+        return "searching";
+      } else if (match) {
+        stream.pos = match.index;
+      } else {
+        stream.skipToEnd();
+      }
+    }};
+  }
+
+  function SearchState() {
+    this.posFrom = this.posTo = this.lastQuery = this.query = null;
+    this.overlay = null;
+  }
+
+  function getSearchState(cm) {
+    return cm.state.search || (cm.state.search = new SearchState());
+  }
+
+  function queryCaseInsensitive(query) {
+    return typeof query == "string" && query == query.toLowerCase();
+  }
+
+  function getSearchCursor(cm, query, pos) {
+    // Heuristic: if the query string is all lowercase, do a case insensitive search.
+    return cm.getSearchCursor(query, pos, queryCaseInsensitive(query));
+  }
+
+  function persistentDialog(cm, text, deflt, f) {
+    cm.openDialog(text, f, {
+      value: deflt,
+      selectValueOnOpen: true,
+      closeOnEnter: false,
+      onClose: function() { clearSearch(cm); }
+    });
+  }
+
+  function dialog(cm, text, shortText, deflt, f) {
+    if (cm.openDialog) cm.openDialog(text, f, {value: deflt, selectValueOnOpen: true});
+    else f(prompt(shortText, deflt));
+  }
+
+  function confirmDialog(cm, text, shortText, fs) {
+    if (cm.openConfirm) cm.openConfirm(text, fs);
+    else if (confirm(shortText)) fs[0]();
+  }
+
+  function parseString(string) {
+    return string.replace(/\\(.)/g, function(_, ch) {
+      if (ch == "n") return "\n"
+      if (ch == "r") return "\r"
+      return ch
+    })
+  }
+
+  function parseQuery(query) {
+    var isRE = query.match(/^\/(.*)\/([a-z]*)$/);
+    if (isRE) {
+      try { query = new RegExp(isRE[1], isRE[2].indexOf("i") == -1 ? "" : "i"); }
+      catch(e) {} // Not a regular expression after all, do a string search
+    } else {
+      query = parseString(query)
+    }
+    if (typeof query == "string" ? query == "" : query.test(""))
+      query = /x^/;
+    return query;
+  }
+
+  var queryDialog =
+    'Search: <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';
+
+  function startSearch(cm, state, query) {
+    state.queryText = query;
+    state.query = parseQuery(query);
+    cm.removeOverlay(state.overlay, queryCaseInsensitive(state.query));
+    state.overlay = searchOverlay(state.query, queryCaseInsensitive(state.query));
+    cm.addOverlay(state.overlay);
+    if (cm.showMatchesOnScrollbar) {
+      if (state.annotate) { state.annotate.clear(); state.annotate = null; }
+      state.annotate = cm.showMatchesOnScrollbar(state.query, queryCaseInsensitive(state.query));
+    }
+  }
+
+  function doSearch(cm, rev, persistent) {
+    var state = getSearchState(cm);
+    if (state.query) return findNext(cm, rev);
+    var q = cm.getSelection() || state.lastQuery;
+    if (persistent && cm.openDialog) {
+      var hiding = null
+      persistentDialog(cm, queryDialog, q, function(query, event) {
+        CodeMirror.e_stop(event);
+        if (!query) return;
+        if (query != state.queryText) startSearch(cm, state, query);
+        if (hiding) hiding.style.opacity = 1
+        findNext(cm, event.shiftKey, function(_, to) {
+          var dialog
+          if (to.line < 3 && document.querySelector &&
+              (dialog = cm.display.wrapper.querySelector(".CodeMirror-dialog")) &&
+              dialog.getBoundingClientRect().bottom - 4 > cm.cursorCoords(to, "window").top)
+            (hiding = dialog).style.opacity = .4
+        })
+      });
+    } else {
+      dialog(cm, queryDialog, "Search for:", q, function(query) {
+        if (query && !state.query) cm.operation(function() {
+          startSearch(cm, state, query);
+          state.posFrom = state.posTo = cm.getCursor();
+          findNext(cm, rev);
+        });
+      });
+    }
+  }
+
+  function findNext(cm, rev, callback) {cm.operation(function() {
+    var state = getSearchState(cm);
+    var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
+    if (!cursor.find(rev)) {
+      cursor = getSearchCursor(cm, state.query, rev ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0));
+      if (!cursor.find(rev)) return;
+    }
+    cm.setSelection(cursor.from(), cursor.to());
+    cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 20);
+    state.posFrom = cursor.from(); state.posTo = cursor.to();
+    if (callback) callback(cursor.from(), cursor.to())
+  });}
+
+  function clearSearch(cm) {cm.operation(function() {
+    var state = getSearchState(cm);
+    state.lastQuery = state.query;
+    if (!state.query) return;
+    state.query = state.queryText = null;
+    cm.removeOverlay(state.overlay);
+    if (state.annotate) { state.annotate.clear(); state.annotate = null; }
+  });}
+
+  var replaceQueryDialog =
+    ' <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';
+  var replacementQueryDialog = 'With: <input type="text" style="width: 10em" class="CodeMirror-search-field"/>';
+  var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>All</button> <button>Stop</button>";
+
+  function replaceAll(cm, query, text) {
+    cm.operation(function() {
+      for (var cursor = getSearchCursor(cm, query); cursor.findNext();) {
+        if (typeof query != "string") {
+          var match = cm.getRange(cursor.from(), cursor.to()).match(query);
+          cursor.replace(text.replace(/\$(\d)/g, function(_, i) {return match[i];}));
+        } else cursor.replace(text);
+      }
+    });
+  }
+
+  function replace(cm, all) {
+    if (cm.getOption("readOnly")) return;
+    var query = cm.getSelection() || getSearchState(cm).lastQuery;
+    var dialogText = all ? "Replace all:" : "Replace:"
+    dialog(cm, dialogText + replaceQueryDialog, dialogText, query, function(query) {
+      if (!query) return;
+      query = parseQuery(query);
+      dialog(cm, replacementQueryDialog, "Replace with:", "", function(text) {
+        text = parseString(text)
+        if (all) {
+          replaceAll(cm, query, text)
+        } else {
+          clearSearch(cm);
+          var cursor = getSearchCursor(cm, query, cm.getCursor());
+          var advance = function() {
+            var start = cursor.from(), match;
+            if (!(match = cursor.findNext())) {
+              cursor = getSearchCursor(cm, query);
+              if (!(match = cursor.findNext()) ||
+                  (start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
+            }
+            cm.setSelection(cursor.from(), cursor.to());
+            cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
+            confirmDialog(cm, doReplaceConfirm, "Replace?",
+                          [function() {doReplace(match);}, advance,
+                           function() {replaceAll(cm, query, text)}]);
+          };
+          var doReplace = function(match) {
+            cursor.replace(typeof query == "string" ? text :
+                           text.replace(/\$(\d)/g, function(_, i) {return match[i];}));
+            advance();
+          };
+          advance();
+        }
+      });
+    });
+  }
+
+  CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);};
+  CodeMirror.commands.findPersistent = function(cm) {clearSearch(cm); doSearch(cm, false, true);};
+  CodeMirror.commands.findNext = doSearch;
+  CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);};
+  CodeMirror.commands.clearSearch = clearSearch;
+  CodeMirror.commands.replace = replace;
+  CodeMirror.commands.replaceAll = function(cm) {replace(cm, true);};
+});

+ 4 - 4
src/lib/CodeMirror/addon/search/searchcursor.js

@@ -148,10 +148,10 @@
     from: function() {if (this.atOccurrence) return this.pos.from;},
     from: function() {if (this.atOccurrence) return this.pos.from;},
     to: function() {if (this.atOccurrence) return this.pos.to;},
     to: function() {if (this.atOccurrence) return this.pos.to;},
 
 
-    replace: function(newText) {
+    replace: function(newText, origin) {
       if (!this.atOccurrence) return;
       if (!this.atOccurrence) return;
       var lines = CodeMirror.splitLines(newText);
       var lines = CodeMirror.splitLines(newText);
-      this.doc.replaceRange(lines, this.pos.from, this.pos.to);
+      this.doc.replaceRange(lines, this.pos.from, this.pos.to, origin);
       this.pos.to = Pos(this.pos.from.line + lines.length - 1,
       this.pos.to = Pos(this.pos.from.line + lines.length - 1,
                         lines[lines.length - 1].length + (lines.length == 1 ? this.pos.from.ch : 0));
                         lines[lines.length - 1].length + (lines.length == 1 ? this.pos.from.ch : 0));
     }
     }
@@ -177,9 +177,9 @@
   });
   });
 
 
   CodeMirror.defineExtension("selectMatches", function(query, caseFold) {
   CodeMirror.defineExtension("selectMatches", function(query, caseFold) {
-    var ranges = [], next;
+    var ranges = [];
     var cur = this.getSearchCursor(query, this.getCursor("from"), caseFold);
     var cur = this.getSearchCursor(query, this.getCursor("from"), caseFold);
-    while (next = cur.findNext()) {
+    while (cur.findNext()) {
       if (CodeMirror.cmpPos(cur.to(), this.getCursor("to")) > 0) break;
       if (CodeMirror.cmpPos(cur.to(), this.getCursor("to")) > 0) break;
       ranges.push({anchor: cur.from(), head: cur.to()});
       ranges.push({anchor: cur.from(), head: cur.to()});
     }
     }

+ 65 - 40
src/lib/CodeMirror/lib/codemirror.css

@@ -4,6 +4,7 @@
   /* Set height, width, borders, and global font properties here */
   /* Set height, width, borders, and global font properties here */
   font-family: monospace;
   font-family: monospace;
   height: 300px;
   height: 300px;
+  color: black;
 }
 }
 
 
 /* PADDING */
 /* PADDING */
@@ -32,8 +33,7 @@
   min-width: 20px;
   min-width: 20px;
   text-align: right;
   text-align: right;
   color: #999;
   color: #999;
-  -moz-box-sizing: content-box;
-  box-sizing: content-box;
+  white-space: nowrap;
 }
 }
 
 
 .CodeMirror-guttermarker { color: black; }
 .CodeMirror-guttermarker { color: black; }
@@ -41,19 +41,21 @@
 
 
 /* CURSOR */
 /* CURSOR */
 
 
-.CodeMirror div.CodeMirror-cursor {
+.CodeMirror-cursor {
   border-left: 1px solid black;
   border-left: 1px solid black;
+  border-right: none;
+  width: 0;
 }
 }
 /* Shown when moving in bi-directional text */
 /* Shown when moving in bi-directional text */
 .CodeMirror div.CodeMirror-secondarycursor {
 .CodeMirror div.CodeMirror-secondarycursor {
   border-left: 1px solid silver;
   border-left: 1px solid silver;
 }
 }
-.CodeMirror.cm-fat-cursor div.CodeMirror-cursor {
+.cm-fat-cursor .CodeMirror-cursor {
   width: auto;
   width: auto;
   border: 0;
   border: 0;
   background: #7e7;
   background: #7e7;
 }
 }
-.CodeMirror.cm-fat-cursor div.CodeMirror-cursors {
+.cm-fat-cursor div.CodeMirror-cursors {
   z-index: 1;
   z-index: 1;
 }
 }
 
 
@@ -63,25 +65,26 @@
   -webkit-animation: blink 1.06s steps(1) infinite;
   -webkit-animation: blink 1.06s steps(1) infinite;
   -moz-animation: blink 1.06s steps(1) infinite;
   -moz-animation: blink 1.06s steps(1) infinite;
   animation: blink 1.06s steps(1) infinite;
   animation: blink 1.06s steps(1) infinite;
+  background-color: #7e7;
 }
 }
 @-moz-keyframes blink {
 @-moz-keyframes blink {
-  0% { background: #7e7; }
-  50% { background: none; }
-  100% { background: #7e7; }
+  0% {}
+  50% { background-color: transparent; }
+  100% {}
 }
 }
 @-webkit-keyframes blink {
 @-webkit-keyframes blink {
-  0% { background: #7e7; }
-  50% { background: none; }
-  100% { background: #7e7; }
+  0% {}
+  50% { background-color: transparent; }
+  100% {}
 }
 }
 @keyframes blink {
 @keyframes blink {
-  0% { background: #7e7; }
-  50% { background: none; }
-  100% { background: #7e7; }
+  0% {}
+  50% { background-color: transparent; }
+  100% {}
 }
 }
 
 
 /* Can style cursor different in overwrite (non-insert) mode */
 /* Can style cursor different in overwrite (non-insert) mode */
-div.CodeMirror-overwrite div.CodeMirror-cursor {}
+.CodeMirror-overwrite .CodeMirror-cursor {}
 
 
 .cm-tab { display: inline-block; text-decoration: inherit; }
 .cm-tab { display: inline-block; text-decoration: inherit; }
 
 
@@ -92,6 +95,15 @@ div.CodeMirror-overwrite div.CodeMirror-cursor {}
 
 
 /* DEFAULT THEME */
 /* DEFAULT THEME */
 
 
+.cm-s-default .cm-header {color: blue;}
+.cm-s-default .cm-quote {color: #090;}
+.cm-negative {color: #d44;}
+.cm-positive {color: #292;}
+.cm-header, .cm-strong {font-weight: bold;}
+.cm-em {font-style: italic;}
+.cm-link {text-decoration: underline;}
+.cm-strikethrough {text-decoration: line-through;}
+
 .cm-s-default .cm-keyword {color: #708;}
 .cm-s-default .cm-keyword {color: #708;}
 .cm-s-default .cm-atom {color: #219;}
 .cm-s-default .cm-atom {color: #219;}
 .cm-s-default .cm-number {color: #164;}
 .cm-s-default .cm-number {color: #164;}
@@ -111,21 +123,14 @@ div.CodeMirror-overwrite div.CodeMirror-cursor {}
 .cm-s-default .cm-bracket {color: #997;}
 .cm-s-default .cm-bracket {color: #997;}
 .cm-s-default .cm-tag {color: #170;}
 .cm-s-default .cm-tag {color: #170;}
 .cm-s-default .cm-attribute {color: #00c;}
 .cm-s-default .cm-attribute {color: #00c;}
-.cm-s-default .cm-header {color: blue;}
-.cm-s-default .cm-quote {color: #090;}
 .cm-s-default .cm-hr {color: #999;}
 .cm-s-default .cm-hr {color: #999;}
 .cm-s-default .cm-link {color: #00c;}
 .cm-s-default .cm-link {color: #00c;}
 
 
-.cm-negative {color: #d44;}
-.cm-positive {color: #292;}
-.cm-header, .cm-strong {font-weight: bold;}
-.cm-em {font-style: italic;}
-.cm-link {text-decoration: underline;}
-.cm-strikethrough {text-decoration: line-through;}
-
 .cm-s-default .cm-error {color: #f00;}
 .cm-s-default .cm-error {color: #f00;}
 .cm-invalidchar {color: #f00;}
 .cm-invalidchar {color: #f00;}
 
 
+.CodeMirror-composing { border-bottom: 2px solid; }
+
 /* Default styles for common addons */
 /* Default styles for common addons */
 
 
 div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
 div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
@@ -139,15 +144,13 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
    the editor. You probably shouldn't touch them. */
    the editor. You probably shouldn't touch them. */
 
 
 .CodeMirror {
 .CodeMirror {
-  line-height: 1;
   position: relative;
   position: relative;
   overflow: hidden;
   overflow: hidden;
   background: white;
   background: white;
-  color: black;
 }
 }
 
 
 .CodeMirror-scroll {
 .CodeMirror-scroll {
-  overflow: scroll;
+  overflow: scroll !important; /* Things will break if this is overridden */
   /* 30px is the magic margin used to hide the element's real scrollbars */
   /* 30px is the magic margin used to hide the element's real scrollbars */
   /* See overflow: hidden in .CodeMirror */
   /* See overflow: hidden in .CodeMirror */
   margin-bottom: -30px; margin-right: -30px;
   margin-bottom: -30px; margin-right: -30px;
@@ -155,14 +158,10 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
   height: 100%;
   height: 100%;
   outline: none; /* Prevent dragging from highlighting the element */
   outline: none; /* Prevent dragging from highlighting the element */
   position: relative;
   position: relative;
-  -moz-box-sizing: content-box;
-  box-sizing: content-box;
 }
 }
 .CodeMirror-sizer {
 .CodeMirror-sizer {
   position: relative;
   position: relative;
   border-right: 30px solid transparent;
   border-right: 30px solid transparent;
-  -moz-box-sizing: content-box;
-  box-sizing: content-box;
 }
 }
 
 
 /* The fake, visible scrollbars. Used to force redraw during scrolling
 /* The fake, visible scrollbars. Used to force redraw during scrolling
@@ -197,8 +196,6 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
 .CodeMirror-gutter {
 .CodeMirror-gutter {
   white-space: normal;
   white-space: normal;
   height: 100%;
   height: 100%;
-  -moz-box-sizing: content-box;
-  box-sizing: content-box;
   display: inline-block;
   display: inline-block;
   margin-bottom: -30px;
   margin-bottom: -30px;
   /* Hack to make IE7 behave */
   /* Hack to make IE7 behave */
@@ -208,13 +205,24 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
 .CodeMirror-gutter-wrapper {
 .CodeMirror-gutter-wrapper {
   position: absolute;
   position: absolute;
   z-index: 4;
   z-index: 4;
-  height: 100%;
+  background: none !important;
+  border: none !important;
+}
+.CodeMirror-gutter-background {
+  position: absolute;
+  top: 0; bottom: 0;
+  z-index: 4;
 }
 }
 .CodeMirror-gutter-elt {
 .CodeMirror-gutter-elt {
   position: absolute;
   position: absolute;
   cursor: default;
   cursor: default;
   z-index: 4;
   z-index: 4;
 }
 }
+.CodeMirror-gutter-wrapper {
+  -webkit-user-select: none;
+  -moz-user-select: none;
+  user-select: none;
+}
 
 
 .CodeMirror-lines {
 .CodeMirror-lines {
   cursor: text;
   cursor: text;
@@ -235,6 +243,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
   z-index: 2;
   z-index: 2;
   position: relative;
   position: relative;
   overflow: visible;
   overflow: visible;
+  -webkit-tap-highlight-color: transparent;
 }
 }
 .CodeMirror-wrap pre {
 .CodeMirror-wrap pre {
   word-wrap: break-word;
   word-wrap: break-word;
@@ -256,6 +265,20 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
 
 
 .CodeMirror-widget {}
 .CodeMirror-widget {}
 
 
+.CodeMirror-code {
+  outline: none;
+}
+
+/* Force content-box sizing for the elements where we expect it */
+.CodeMirror-scroll,
+.CodeMirror-sizer,
+.CodeMirror-gutter,
+.CodeMirror-gutters,
+.CodeMirror-linenumber {
+  -moz-box-sizing: content-box;
+  box-sizing: content-box;
+}
+
 .CodeMirror-measure {
 .CodeMirror-measure {
   position: absolute;
   position: absolute;
   width: 100%;
   width: 100%;
@@ -263,19 +286,19 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
   overflow: hidden;
   overflow: hidden;
   visibility: hidden;
   visibility: hidden;
 }
 }
-.CodeMirror-measure pre { position: static; }
 
 
-.CodeMirror div.CodeMirror-cursor {
-  position: absolute;
-  border-right: none;
-  width: 0;
-}
+.CodeMirror-cursor { position: absolute; }
+.CodeMirror-measure pre { position: static; }
 
 
 div.CodeMirror-cursors {
 div.CodeMirror-cursors {
   visibility: hidden;
   visibility: hidden;
   position: relative;
   position: relative;
   z-index: 3;
   z-index: 3;
 }
 }
+div.CodeMirror-dragcursors {
+  visibility: visible;
+}
+
 .CodeMirror-focused div.CodeMirror-cursors {
 .CodeMirror-focused div.CodeMirror-cursors {
   visibility: visible;
   visibility: visible;
 }
 }
@@ -283,6 +306,8 @@ div.CodeMirror-cursors {
 .CodeMirror-selected { background: #d9d9d9; }
 .CodeMirror-selected { background: #d9d9d9; }
 .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
 .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
 .CodeMirror-crosshair { cursor: crosshair; }
 .CodeMirror-crosshair { cursor: crosshair; }
+.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }
+.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; }
 
 
 .cm-searching {
 .cm-searching {
   background: #ffa;
   background: #ffa;

Plik diff jest za duży
+ 1033 - 100
src/lib/CodeMirror/lib/codemirror.js


+ 56 - 19
src/lib/CodeMirror/mode/javascript/javascript.js

@@ -30,13 +30,13 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
 
 
     var jsKeywords = {
     var jsKeywords = {
       "if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
       "if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
-      "return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C, "debugger": C,
+      "return": C, "break": C, "continue": C, "new": kw("new"), "delete": C, "throw": C, "debugger": C,
       "var": kw("var"), "const": kw("var"), "let": kw("var"),
       "var": kw("var"), "const": kw("var"), "let": kw("var"),
       "function": kw("function"), "catch": kw("catch"),
       "function": kw("function"), "catch": kw("catch"),
       "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
       "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
       "in": operator, "typeof": operator, "instanceof": operator,
       "in": operator, "typeof": operator, "instanceof": operator,
       "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
       "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
-      "this": kw("this"), "module": kw("module"), "class": kw("class"), "super": kw("atom"),
+      "this": kw("this"), "class": kw("class"), "super": kw("atom"),
       "yield": C, "export": kw("export"), "import": kw("import"), "extends": C
       "yield": C, "export": kw("export"), "import": kw("import"), "extends": C
     };
     };
 
 
@@ -56,7 +56,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
         "static": kw("static"),
         "static": kw("static"),
 
 
         // types
         // types
-        "string": type, "number": type, "bool": type, "any": type
+        "string": type, "number": type, "boolean": type, "any": type
       };
       };
 
 
       for (var attr in tsKeywords) {
       for (var attr in tsKeywords) {
@@ -105,6 +105,12 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
     } else if (ch == "0" && stream.eat(/x/i)) {
     } else if (ch == "0" && stream.eat(/x/i)) {
       stream.eatWhile(/[\da-f]/i);
       stream.eatWhile(/[\da-f]/i);
       return ret("number", "number");
       return ret("number", "number");
+    } else if (ch == "0" && stream.eat(/o/i)) {
+      stream.eatWhile(/[0-7]/i);
+      return ret("number", "number");
+    } else if (ch == "0" && stream.eat(/b/i)) {
+      stream.eatWhile(/[01]/i);
+      return ret("number", "number");
     } else if (/\d/.test(ch)) {
     } else if (/\d/.test(ch)) {
       stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
       stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
       return ret("number", "number");
       return ret("number", "number");
@@ -115,10 +121,9 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
       } else if (stream.eat("/")) {
       } else if (stream.eat("/")) {
         stream.skipToEnd();
         stream.skipToEnd();
         return ret("comment", "comment");
         return ret("comment", "comment");
-      } else if (state.lastType == "operator" || state.lastType == "keyword c" ||
-               state.lastType == "sof" || /^[\[{}\(,;:]$/.test(state.lastType)) {
+      } else if (/^(?:operator|sof|keyword c|case|new|[\[{}\(,;:])$/.test(state.lastType)) {
         readRegexp(stream);
         readRegexp(stream);
-        stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla
+        stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
         return ret("regexp", "string-2");
         return ret("regexp", "string-2");
       } else {
       } else {
         stream.eatWhile(isOperatorChar);
         stream.eatWhile(isOperatorChar);
@@ -205,6 +210,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
         ++depth;
         ++depth;
       } else if (wordRE.test(ch)) {
       } else if (wordRE.test(ch)) {
         sawSomething = true;
         sawSomething = true;
+      } else if (/["'\/]/.test(ch)) {
+        return;
       } else if (sawSomething && !depth) {
       } else if (sawSomething && !depth) {
         ++pos;
         ++pos;
         break;
         break;
@@ -273,8 +280,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
       return false;
       return false;
     }
     }
     var state = cx.state;
     var state = cx.state;
+    cx.marked = "def";
     if (state.context) {
     if (state.context) {
-      cx.marked = "def";
       if (inList(state.localVars)) return;
       if (inList(state.localVars)) return;
       state.localVars = {name: varname, next: state.localVars};
       state.localVars = {name: varname, next: state.localVars};
     } else {
     } else {
@@ -345,10 +352,9 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
     if (type == "default") return cont(expect(":"));
     if (type == "default") return cont(expect(":"));
     if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
     if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
                                      statement, poplex, popcontext);
                                      statement, poplex, popcontext);
-    if (type == "module") return cont(pushlex("form"), pushcontext, afterModule, popcontext, poplex);
     if (type == "class") return cont(pushlex("form"), className, poplex);
     if (type == "class") return cont(pushlex("form"), className, poplex);
-    if (type == "export") return cont(pushlex("form"), afterExport, poplex);
-    if (type == "import") return cont(pushlex("form"), afterImport, poplex);
+    if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
+    if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
     return pass(pushlex("stat"), expression, expect(";"), poplex);
     return pass(pushlex("stat"), expression, expect(";"), poplex);
   }
   }
   function expression(type) {
   function expression(type) {
@@ -372,7 +378,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
     if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
     if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
     if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
     if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
     if (type == "{") return contCommasep(objprop, "}", null, maybeop);
     if (type == "{") return contCommasep(objprop, "}", null, maybeop);
-    if (type == "quasi") { return pass(quasi, maybeop); }
+    if (type == "quasi") return pass(quasi, maybeop);
+    if (type == "new") return cont(maybeTarget(noComma));
     return cont();
     return cont();
   }
   }
   function maybeexpression(type) {
   function maybeexpression(type) {
@@ -423,6 +430,18 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
     findFatArrow(cx.stream, cx.state);
     findFatArrow(cx.stream, cx.state);
     return pass(type == "{" ? statement : expressionNoComma);
     return pass(type == "{" ? statement : expressionNoComma);
   }
   }
+  function maybeTarget(noComma) {
+    return function(type) {
+      if (type == ".") return cont(noComma ? targetNoComma : target);
+      else return pass(noComma ? expressionNoComma : expression);
+    };
+  }
+  function target(_, value) {
+    if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorComma); }
+  }
+  function targetNoComma(_, value) {
+    if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorNoComma); }
+  }
   function maybelabel(type) {
   function maybelabel(type) {
     if (type == ":") return cont(poplex, statement);
     if (type == ":") return cont(poplex, statement);
     return pass(maybeoperatorComma, expect(";"), poplex);
     return pass(maybeoperatorComma, expect(";"), poplex);
@@ -442,6 +461,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
       return cont(afterprop);
       return cont(afterprop);
     } else if (type == "[") {
     } else if (type == "[") {
       return cont(expression, expect("]"), afterprop);
       return cont(expression, expect("]"), afterprop);
+    } else if (type == "spread") {
+      return cont(expression);
     }
     }
   }
   }
   function getterSetter(type) {
   function getterSetter(type) {
@@ -480,14 +501,18 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
   function maybetype(type) {
   function maybetype(type) {
     if (isTS && type == ":") return cont(typedef);
     if (isTS && type == ":") return cont(typedef);
   }
   }
+  function maybedefault(_, value) {
+    if (value == "=") return cont(expressionNoComma);
+  }
   function typedef(type) {
   function typedef(type) {
-    if (type == "variable"){cx.marked = "variable-3"; return cont();}
+    if (type == "variable") {cx.marked = "variable-3"; return cont();}
   }
   }
   function vardef() {
   function vardef() {
     return pass(pattern, maybetype, maybeAssign, vardefCont);
     return pass(pattern, maybetype, maybeAssign, vardefCont);
   }
   }
   function pattern(type, value) {
   function pattern(type, value) {
     if (type == "variable") { register(value); return cont(); }
     if (type == "variable") { register(value); return cont(); }
+    if (type == "spread") return cont(pattern);
     if (type == "[") return contCommasep(pattern, "]");
     if (type == "[") return contCommasep(pattern, "]");
     if (type == "{") return contCommasep(proppattern, "}");
     if (type == "{") return contCommasep(proppattern, "}");
   }
   }
@@ -497,6 +522,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
       return cont(maybeAssign);
       return cont(maybeAssign);
     }
     }
     if (type == "variable") cx.marked = "property";
     if (type == "variable") cx.marked = "property";
+    if (type == "spread") return cont(pattern);
     return cont(expect(":"), pattern, maybeAssign);
     return cont(expect(":"), pattern, maybeAssign);
   }
   }
   function maybeAssign(_type, value) {
   function maybeAssign(_type, value) {
@@ -536,7 +562,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
   }
   }
   function funarg(type) {
   function funarg(type) {
     if (type == "spread") return cont(funarg);
     if (type == "spread") return cont(funarg);
-    return pass(pattern, maybetype);
+    return pass(pattern, maybetype, maybedefault);
   }
   }
   function className(type, value) {
   function className(type, value) {
     if (type == "variable") {register(value); return cont(classNameAfter);}
     if (type == "variable") {register(value); return cont(classNameAfter);}
@@ -547,6 +573,10 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
   }
   }
   function classBody(type, value) {
   function classBody(type, value) {
     if (type == "variable" || cx.style == "keyword") {
     if (type == "variable" || cx.style == "keyword") {
+      if (value == "static") {
+        cx.marked = "keyword";
+        return cont(classBody);
+      }
       cx.marked = "property";
       cx.marked = "property";
       if (value == "get" || value == "set") return cont(classGetterSetter, functiondef, classBody);
       if (value == "get" || value == "set") return cont(classGetterSetter, functiondef, classBody);
       return cont(functiondef, classBody);
       return cont(functiondef, classBody);
@@ -563,10 +593,6 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
     cx.marked = "property";
     cx.marked = "property";
     return cont();
     return cont();
   }
   }
-  function afterModule(type, value) {
-    if (type == "string") return cont(statement);
-    if (type == "variable") { register(value); return cont(maybeFrom); }
-  }
   function afterExport(_type, value) {
   function afterExport(_type, value) {
     if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
     if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
     if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
     if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
@@ -579,7 +605,11 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
   function importSpec(type, value) {
   function importSpec(type, value) {
     if (type == "{") return contCommasep(importSpec, "}");
     if (type == "{") return contCommasep(importSpec, "}");
     if (type == "variable") register(value);
     if (type == "variable") register(value);
-    return cont();
+    if (value == "*") cx.marked = "keyword";
+    return cont(maybeAs);
+  }
+  function maybeAs(_type, value) {
+    if (value == "as") { cx.marked = "keyword"; return cont(importSpec); }
   }
   }
   function maybeFrom(_type, value) {
   function maybeFrom(_type, value) {
     if (value == "from") { cx.marked = "keyword"; return cont(expression); }
     if (value == "from") { cx.marked = "keyword"; return cont(expression); }
@@ -598,6 +628,12 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
     if (type == "if") return cont(expression, comprehension);
     if (type == "if") return cont(expression, comprehension);
   }
   }
 
 
+  function isContinuedStatement(state, textAfter) {
+    return state.lastType == "operator" || state.lastType == "," ||
+      isOperatorChar.test(textAfter.charAt(0)) ||
+      /[,.]/.test(textAfter.charAt(0));
+  }
+
   // Interface
   // Interface
 
 
   return {
   return {
@@ -649,7 +685,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
       else if (type == "form" && firstChar == "{") return lexical.indented;
       else if (type == "form" && firstChar == "{") return lexical.indented;
       else if (type == "form") return lexical.indented + indentUnit;
       else if (type == "form") return lexical.indented + indentUnit;
       else if (type == "stat")
       else if (type == "stat")
-        return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? statementIndent || indentUnit : 0);
+        return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0);
       else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false)
       else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false)
         return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
         return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
       else if (lexical.align) return lexical.column + (closing ? 0 : 1);
       else if (lexical.align) return lexical.column + (closing ? 0 : 1);
@@ -661,6 +697,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
     blockCommentEnd: jsonMode ? null : "*/",
     blockCommentEnd: jsonMode ? null : "*/",
     lineComment: jsonMode ? null : "//",
     lineComment: jsonMode ? null : "//",
     fold: "brace",
     fold: "brace",
+    closeBrackets: "()[]{}''\"\"``",
 
 
     helperType: jsonMode ? "json" : "javascript",
     helperType: jsonMode ? "json" : "javascript",
     jsonldMode: jsonldMode,
     jsonldMode: jsonldMode,

Plik diff jest za duży
+ 3 - 0
src/lib/font-awesome/css/font-awesome.min.css


Plik diff jest za duży
+ 0 - 3
src/lib/font-awesome/font-awesome.min.css


BIN
src/lib/font-awesome/fontawesome-webfont.woff2


BIN
src/lib/font-awesome/fonts/fontawesome-webfont.woff2


+ 7 - 1
src/lib/zip.js/z-worker.js

@@ -94,7 +94,13 @@
 		}
 		}
 		if (!isAppend && (task.crcInput || task.crcOutput))
 		if (!isAppend && (task.crcInput || task.crcOutput))
 			rmsg.crc = task.crc.get();
 			rmsg.crc = task.crc.get();
-		postMessage(rmsg, transferables);
+		
+		// posting a message with transferables will fail on IE10
+		try {
+			postMessage(rmsg, transferables);
+		} catch(ex) {
+			postMessage(rmsg); // retry without transferables
+		}
 	}
 	}
 
 
 	function onError(type, sn, e) {
 	function onError(type, sn, e) {

+ 9 - 2
src/lib/zip.js/zip.js

@@ -360,14 +360,21 @@
 
 
 		function step() {
 		function step() {
 			index = chunkIndex * CHUNK_SIZE;
 			index = chunkIndex * CHUNK_SIZE;
-			if (index < size) {
+			// use `<=` instead of `<`, because `size` may be 0.
+			if (index <= size) {
 				reader.readUint8Array(offset + index, Math.min(CHUNK_SIZE, size - index), function(array) {
 				reader.readUint8Array(offset + index, Math.min(CHUNK_SIZE, size - index), function(array) {
 					if (onprogress)
 					if (onprogress)
 						onprogress(index, size);
 						onprogress(index, size);
 					var msg = index === 0 ? initialMessage : {sn : sn};
 					var msg = index === 0 ? initialMessage : {sn : sn};
 					msg.type = 'append';
 					msg.type = 'append';
 					msg.data = array;
 					msg.data = array;
-					worker.postMessage(msg, [array.buffer]);
+					
+					// posting a message with transferables will fail on IE10
+					try {
+						worker.postMessage(msg, [array.buffer]);
+					} catch(ex) {
+						worker.postMessage(msg); // retry without transferables
+					}
 					chunkIndex++;
 					chunkIndex++;
 				}, onreaderror);
 				}, onreaderror);
 			} else {
 			} else {

+ 2 - 2
src/mylib/CodeMirror/search.js

@@ -42,8 +42,8 @@
 			dialog = wrap.appendChild(document.createElement("div"));
 			dialog = wrap.appendChild(document.createElement("div"));
 			dialog.className='CodeMirror-dialog';
 			dialog.className='CodeMirror-dialog';
 		}
 		}
-		var text=_('labelSearch')+'<input class=CodeMirror-search placeholder="'+_('labelSearchFor')+'"><button class=CodeMirror-findPrev>&lt;</button><button class=CodeMirror-findNext>&gt;</button><button class=CodeMirror-cancel>&times;</button>',closed=false,iS,iR;
-		if(rep) text+='<br>'+_('labelReplace')+'<input class=CodeMirror-replace placeholder="'+_('labelReplaceWith')+'"><button class=CodeMirror-replaceNext>'+_('buttonReplace')+'</button><button class=CodeMirror-replaceAll>'+_('buttonReplaceAll')+'</button>';
+		var text=_.i18n('labelSearch')+'<input class=CodeMirror-search placeholder="'+_.i18n('labelSearchFor')+'"><button class=CodeMirror-findPrev>&lt;</button><button class=CodeMirror-findNext>&gt;</button><button class=CodeMirror-cancel>&times;</button>',closed=false,iS,iR;
+		if(rep) text+='<br>'+_.i18n('labelReplace')+'<input class=CodeMirror-replace placeholder="'+_.i18n('labelReplaceWith')+'"><button class=CodeMirror-replaceNext>'+_.i18n('buttonReplace')+'</button><button class=CodeMirror-replaceAll>'+_.i18n('buttonReplaceAll')+'</button>';
 		dialog.innerHTML=text;
 		dialog.innerHTML=text;
 		iS=dialog.querySelector('.CodeMirror-search');
 		iS=dialog.querySelector('.CodeMirror-search');
 		CodeMirror.on(dialog.querySelector('.CodeMirror-findNext'), "click", function(e) {findNext(cm);});
 		CodeMirror.on(dialog.querySelector('.CodeMirror-findNext'), "click", function(e) {findNext(cm);});

+ 1 - 1
src/options/index.html

@@ -4,7 +4,7 @@
     <meta charset="utf-8">
     <meta charset="utf-8">
     <title data-i18n="extName"></title>
     <title data-i18n="extName"></title>
     <link rel="shortcut icon" type="image/png" href="/images/icon16.png">
     <link rel="shortcut icon" type="image/png" href="/images/icon16.png">
-    <link rel="stylesheet" href="/lib/font-awesome/font-awesome.min.css">
+    <link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
     <link rel="stylesheet" href="style.css">
     <link rel="stylesheet" href="style.css">
     <script src="/lib/zepto.min.js"></script>
     <script src="/lib/zepto.min.js"></script>
     <script src="/lib/underscore-min.js"></script>
     <script src="/lib/underscore-min.js"></script>

+ 1 - 1
src/popup/index.html

@@ -3,7 +3,7 @@
 	<head>
 	<head>
 		<meta charset="utf-8">
 		<meta charset="utf-8">
 		<title>Popup Menu - Violentmonkey</title>
 		<title>Popup Menu - Violentmonkey</title>
-		<link rel="stylesheet" href="/lib/font-awesome/font-awesome.min.css">
+		<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
     <link rel="stylesheet" href="style.css">
     <link rel="stylesheet" href="style.css">
 		<script src="/lib/zepto.min.js"></script>
 		<script src="/lib/zepto.min.js"></script>
     <script src="/lib/underscore-min.js"></script>
     <script src="/lib/underscore-min.js"></script>

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików