4e347d330ecc5e8dcff367c024911892.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. }); (function() {
  60. ace.require(["ace/ext/spellcheck"], function(m) {
  61. if (typeof module == "object" && typeof exports == "object" && module) {
  62. module.exports = m;
  63. }
  64. });
  65. })();