(CodeMirror)
| 8224 | // convenience. |
| 8225 | |
| 8226 | function addEditorMethods(CodeMirror) { |
| 8227 | var optionHandlers = CodeMirror.optionHandlers; |
| 8228 | |
| 8229 | var helpers = CodeMirror.helpers = {}; |
| 8230 | |
| 8231 | CodeMirror.prototype = { |
| 8232 | constructor: CodeMirror, |
| 8233 | focus: function(){window.focus(); this.display.input.focus();}, |
| 8234 | |
| 8235 | setOption: function(option, value) { |
| 8236 | var options = this.options, old = options[option]; |
| 8237 | if (options[option] == value && option != "mode") { return } |
| 8238 | options[option] = value; |
| 8239 | if (optionHandlers.hasOwnProperty(option)) |
| 8240 | { operation(this, optionHandlers[option])(this, value, old); } |
| 8241 | signal(this, "optionChange", this, option); |
| 8242 | }, |
| 8243 | |
| 8244 | getOption: function(option) {return this.options[option]}, |
| 8245 | getDoc: function() {return this.doc}, |
| 8246 | |
| 8247 | addKeyMap: function(map, bottom) { |
| 8248 | this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map)); |
| 8249 | }, |
| 8250 | removeKeyMap: function(map) { |
| 8251 | var maps = this.state.keyMaps; |
| 8252 | for (var i = 0; i < maps.length; ++i) |
| 8253 | { if (maps[i] == map || maps[i].name == map) { |
| 8254 | maps.splice(i, 1); |
| 8255 | return true |
| 8256 | } } |
| 8257 | }, |
| 8258 | |
| 8259 | addOverlay: methodOp(function(spec, options) { |
| 8260 | var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec); |
| 8261 | if (mode.startState) { throw new Error("Overlays may not be stateful.") } |
| 8262 | insertSorted(this.state.overlays, |
| 8263 | {mode: mode, modeSpec: spec, opaque: options && options.opaque, |
| 8264 | priority: (options && options.priority) || 0}, |
| 8265 | function (overlay) { return overlay.priority; }); |
| 8266 | this.state.modeGen++; |
| 8267 | regChange(this); |
| 8268 | }), |
| 8269 | removeOverlay: methodOp(function(spec) { |
| 8270 | var overlays = this.state.overlays; |
| 8271 | for (var i = 0; i < overlays.length; ++i) { |
| 8272 | var cur = overlays[i].modeSpec; |
| 8273 | if (cur == spec || typeof spec == "string" && cur.name == spec) { |
| 8274 | overlays.splice(i, 1); |
| 8275 | this.state.modeGen++; |
| 8276 | regChange(this); |
| 8277 | return |
| 8278 | } |
| 8279 | } |
| 8280 | }), |
| 8281 | |
| 8282 | indentLine: methodOp(function(n, dir, aggressive) { |
| 8283 | if (typeof dir != "string" && typeof dir != "number") { |
no test coverage detected