ext-linking.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ace.define("ace/ext/linking",[], function(require, exports, module) {
  2. var Editor = require("ace/editor").Editor;
  3. 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. });
  48. (function() {
  49. ace.require(["ace/ext/linking"], function(m) {
  50. if (typeof module == "object" && typeof exports == "object" && module) {
  51. module.exports = m;
  52. }
  53. });
  54. })();