You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.8 KiB

12 months ago
  1. ace.define("ace/ext/linking",["require","exports","module","ace/editor","ace/config"], function(acequire, exports, module) {
  2. var Editor = acequire("ace/editor").Editor;
  3. acequire("../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.acequire(["ace/ext/linking"], function() {});
  50. })();