javascript - How do I check if the user's text cursor is between two strings? -
i want check , see if user's (blinking) cursor position between 2 strings in textarea.
handling tab events it's own thing, want know method of handling cursor location in relation tags.
to find inside-tag match, can split text left , right, proper open/close tags in right half. there, it's simple create tab replacement using same halfs:
<textarea>blah <code> code </code> , not.</textarea> <script> function handlekeys(e) { var t,n,s,r, pad=" "; if (e.shiftkey && e.keycode == 32) { t = this.value, n = this.selectionstart, s = this.scrolltop, r = [t.slice(0, n), t.slice(n)]; this.value = r.join(pad); this.selectionstart = this.selectionend = n + pad.length; this.scrolltop = s; e.preventdefault(); } } </script>
pressing tab within code tag insert tab character. should consider providing way folks utilize keyboard escape tab trap, maybe escape key or something.
edit: added scroll resume prepare bug in browsers scroll textarea top when inserting. since it's event fire lot, optimized function ignore non-relevant key-presses (instead of doing work each , every keydown).
javascript jquery regex textarea
No comments:
Post a Comment