Sha256: 3fa222d9e00f3928971cb3c04fec34c912de84acf1361a5d9bbc2a6ad89f7d6e

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

(function() {
  var DEFAULT_BRACKETS = "()[]{}''\"\"";

  CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
    var wasOn = old && old != CodeMirror.Init;
    if (val && !wasOn)
      cm.addKeyMap(buildKeymap(typeof val == "string" ? val : DEFAULT_BRACKETS));
    else if (!val && wasOn)
      cm.removeKeyMap("autoCloseBrackets");
  });

  function buildKeymap(pairs) {
    var map = {name : "autoCloseBrackets"};
    for (var i = 0; i < pairs.length; i += 2) (function(left, right) {
      function maybeOverwrite(cm) {
        var cur = cm.getCursor(), ahead = cm.getRange(cur, CodeMirror.Pos(cur.line, cur.ch + 1));
        if (ahead != right) return CodeMirror.Pass;
        else cm.execCommand("goCharRight");
      }
      map["'" + left + "'"] = function(cm) {
        if (left == right && maybeOverwrite(cm) != CodeMirror.Pass) return;
        var cur = cm.getCursor("start"), ahead = CodeMirror.Pos(cur.line, cur.ch + 1);
        cm.replaceSelection(left + right, {head: ahead, anchor: ahead});
      };
      if (left != right) map["'" + right + "'"] = maybeOverwrite;
    })(pairs.charAt(i), pairs.charAt(i + 1));
    return map;
  }
})();

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
glebtv-ckeditor-4.0.2.7 vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/edit/closebrackets.js
glebtv-ckeditor-4.0.2.6 vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/edit/closebrackets.js
glebtv-ckeditor-4.0.2.5 vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/edit/closebrackets.js
glebtv-ckeditor-4.0.2.4 vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/edit/closebrackets.js
glebtv-ckeditor-4.0.2.2 vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/edit/closebrackets.js
glebtv-ckeditor-4.0.2.1 vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/edit/closebrackets.js
glebtv-ckeditor-4.0.2 vendor/assets/javascripts/ckeditor/plugins/codemirror/js/addon/edit/closebrackets.js