Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes. Use the <code>keydown</code> event and one of the caret-position-in-textarea functions floating around on Stack Overflow. For the key detection, note I've had to use the <code>keydown</code> event rather than the <code>keypress</code> event (which is what should be used for detecting what character has been typed) because IE doesn't fire the <code>keypress</code> events for Ctrl+Alt+L, so this could go wrong on differently mapped keyboards. For the cursor position, I've copied from <a href="https://stackoverflow.com/questions/263743/how-to-get-cursor-position-in-textarea/263796#263796">this answer</a> and have used something similar myself. See these answers for discussion of the problems with this in IE:</p> <p><a href="https://stackoverflow.com/questions/263743/how-to-get-cursor-position-in-textarea">Caret position in textarea, in characters from the start</a> <a href="https://stackoverflow.com/questions/235411/is-there-an-internet-explorer-approved-substitute-for-selectionstart-and-selectio/235582#235582">Is there an Internet Explorer approved substitute for selectionStart and selectionEnd?</a></p> <p>Also, note that you may want to position the cursor somewhere sensible after doing this, which my code doesn't cover.</p> <pre><code>function getCaret(el) { if ("selectionStart" in el) { return el.selectionStart; } else if (document.selection) { el.focus(); var r = document.selection.createRange(); if (r == null) { return 0; } var re = el.createTextRange(), rc = re.duplicate(); re.moveToBookmark(r.getBookmark()); rc.setEndPoint("EndToStart", re); return rc.text.length; } return 0; } var textArea = document.getElementById("yourTextarea"); textArea.onkeydown = function(evt) { evt = evt || window.event; if (evt.ctrlKey &amp;&amp; evt.altKey &amp;&amp; evt.keyCode == 76) { var cursorPos = getCaret(this); this.value = this.value.slice(0, cursorPos) + '&lt;a href="" title=""&gt;&lt;/a&gt;' + this.value.slice(cursorPos) return false; // Prevent any default browser behaviour } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload