ext-linking.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. define("ace/ext/linking",["ace_require","exports","module","ace/editor","ace/config"], function(ace_require, exports, module) {
  2. var Editor = ace_require("../editor").Editor;
  3. ace_require("../config").defineOptions(Editor.prototype, "editor", {
  4. enableLinking: {
  5. set: function(val) {
  6. if (val) {
  7. this.on("click", onClick);
  8. this.on("mousemove", onMouseMove);
  9. } else {
  10. this.off("click", onClick);
  11. this.off("mousemove", onMouseMove);
  12. }
  13. },
  14. value: false
  15. }
  16. });
  17. exports.previousLinkingHover = false;
  18. function onMouseMove(e) {
  19. var editor = e.editor;
  20. var ctrl = e.getAccelKey();
  21. if (ctrl) {
  22. var editor = e.editor;
  23. var docPos = e.getDocumentPosition();
  24. var session = editor.session;
  25. var token = session.getTokenAt(docPos.row, docPos.column);
  26. if (exports.previousLinkingHover && exports.previousLinkingHover != token) {
  27. editor._emit("linkHoverOut");
  28. }
  29. editor._emit("linkHover", {position: docPos, token: token});
  30. exports.previousLinkingHover = token;
  31. } else if (exports.previousLinkingHover) {
  32. editor._emit("linkHoverOut");
  33. exports.previousLinkingHover = false;
  34. }
  35. }
  36. function onClick(e) {
  37. var ctrl = e.getAccelKey();
  38. var button = e.getButton();
  39. if (button == 0 && ctrl) {
  40. var editor = e.editor;
  41. var docPos = e.getDocumentPosition();
  42. var session = editor.session;
  43. var token = session.getTokenAt(docPos.row, docPos.column);
  44. editor._emit("linkClick", {position: docPos, token: token});
  45. }
  46. }
  47. }); (function() {
  48. window.ace_require(["ace/ext/linking"], function(m) {
  49. if (typeof module == "object" && typeof exports == "object" && module) {
  50. module.exports = m;
  51. }
  52. });
  53. })();