JSFiddle - React, Tailwind, and code Playground

by teleclimber

HTML

<div id="ce" contenteditable>
			Click **here** to place the caret, then press the "tab" key to move the caret via the selection API to here. Now press Ctrl + cmd + space to insert an emoji.
		</div>

JavaScript

const ce_elem = document.getElementById( 'ce' );

			document.addEventListener( 'keydown', (event) => {
				if( event.which === 9 ) {
					event.preventDefault();
					window.setTimeout( setCaret, 10 );
				}
			});

			function setCaret() {
				 let sel = window.getSelection();
				 sel.modify( 'move', 'forward', 'sentence' );
			}