| 1 | ace.define("ace/ext/spellcheck",["require","exports","module","ace/lib/event","ace/editor","ace/config"], function(require, exports, module){"use strict"; |
| 2 | var event = require("../lib/event"); |
| 3 | exports.contextMenuHandler = function (e) { |
| 4 | var host = e.target; |
| 5 | var text = host.textInput.getElement(); |
| 6 | if (!host.selection.isEmpty()) |
| 7 | return; |
| 8 | var c = host.getCursorPosition(); |
| 9 | var r = host.session.getWordRange(c.row, c.column); |
| 10 | var w = host.session.getTextRange(r); |
| 11 | host.session.tokenRe.lastIndex = 0; |
| 12 | if (!host.session.tokenRe.test(w)) |
| 13 | return; |
| 14 | var PLACEHOLDER = "\x01\x01"; |
| 15 | var value = w + " " + PLACEHOLDER; |
| 16 | text.value = value; |
| 17 | text.setSelectionRange(w.length, w.length + 1); |
| 18 | text.setSelectionRange(0, 0); |
| 19 | text.setSelectionRange(0, w.length); |
| 20 | var afterKeydown = false; |
| 21 | event.addListener(text, "keydown", function onKeydown() { |
| 22 | event.removeListener(text, "keydown", onKeydown); |
| 23 | afterKeydown = true; |
| 24 | }); |
| 25 | host.textInput.setInputHandler(function (newVal) { |
| 26 | if (newVal == value) |
| 27 | return ''; |
| 28 | if (newVal.lastIndexOf(value, 0) === 0) |
| 29 | return newVal.slice(value.length); |
| 30 | if (newVal.substr(text.selectionEnd) == value) |
| 31 | return newVal.slice(0, -value.length); |
| 32 | if (newVal.slice(-2) == PLACEHOLDER) { |
| 33 | var val = newVal.slice(0, -2); |
| 34 | if (val.slice(-1) == " ") { |
| 35 | if (afterKeydown) |
| 36 | return val.substring(0, text.selectionEnd); |
| 37 | val = val.slice(0, -1); |
| 38 | host.session.replace(r, val); |
| 39 | return ""; |
| 40 | } |
| 41 | } |
| 42 | return newVal; |
| 43 | }); |
| 44 | }; |
| 45 | var Editor = require("../editor").Editor; |
| 46 | require("../config").defineOptions(Editor.prototype, "editor", { |
| 47 | spellcheck: { |
| 48 | set: function (val) { |
| 49 | var text = this.textInput.getElement(); |
| 50 | text.spellcheck = !!val; |
| 51 | if (!val) |
| 52 | this.removeListener("nativecontextmenu", exports.contextMenuHandler); |
| 53 | else |
| 54 | this.on("nativecontextmenu", exports.contextMenuHandler); |
| 55 | }, |
| 56 | value: true |
| 57 | } |
| 58 | }); |
| 59 | |
| 60 | }); (function() { |
| 61 | ace.require(["ace/ext/spellcheck"], function(m) { |
| 62 | if (typeof module == "object" && typeof exports == "object" && module) { |
| 63 | module.exports = m; |
| 64 | } |
| 65 | }); |
| 66 | })(); |
| 67 |