ext-linking.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ace.define("ace/ext/linking",["require","exports","module","ace/editor","ace/config"], 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. function onMouseMove(e) {
  18. var editor = e.editor;
  19. var ctrl = e.getAccelKey();
  20. if (ctrl) {
  21. var editor = e.editor;
  22. var docPos = e.getDocumentPosition();
  23. var session = editor.session;
  24. var token = session.getTokenAt(docPos.row, docPos.column);
  25. editor._emit("linkHover", {position: docPos, token: token});
  26. }
  27. }
  28. function onClick(e) {
  29. var ctrl = e.getAccelKey();
  30. var button = e.getButton();
  31. if (button == 0 && ctrl) {
  32. var editor = e.editor;
  33. var docPos = e.getDocumentPosition();
  34. var session = editor.session;
  35. var token = session.getTokenAt(docPos.row, docPos.column);
  36. editor._emit("linkClick", {position: docPos, token: token});
  37. }
  38. }
  39. });
  40. (function() {
  41. ace.require(["ace/ext/linking"], function() {});
  42. })();