insomnia/app/ui/components/codemirror/extensions/clickable.js
Gregory Schier 62719f3201 More 5.0 Fixes and Stuff (#134)
* Fix OAuth token, new request content-type, and more

* better error messaging around invalid Curl opts

* Make XFERINFOFUNCTION an optional option

* Fix content-type change prompt and double quotes in prettify

* Don't send Expect header on file upload

* Remove dead code

* Base64 tag

* Fix HTML entities in URL clicks

* Fix curl paste
2017-04-07 11:10:15 -07:00

31 lines
858 B
JavaScript

import CodeMirror from 'codemirror';
import 'codemirror/addon/mode/overlay';
import {AllHtmlEntities} from 'html-entities';
import {FLEXIBLE_URL_REGEX} from '../../../../common/constants';
const entities = new AllHtmlEntities();
CodeMirror.defineExtension('makeLinksClickable', function (handleClick) {
// Only add the click mode if we have links to click
this.addOverlay({
token: function (stream, state) {
if (stream.match(FLEXIBLE_URL_REGEX, true)) {
return 'clickable';
}
while (stream.next() != null) {
if (stream.match(FLEXIBLE_URL_REGEX, false)) break;
}
return null;
}
});
this.getWrapperElement().addEventListener('click', e => {
const cls = e.target.className;
if (cls.indexOf('cm-clickable') >= 0) {
handleClick(entities.decode(e.target.innerHTML));
}
});
});