Allows manipulation of the caret position in a text box or a contenteditable element. Ported from jquery-caret.
Allows manipulation of the caret position in a text box or a contenteditable element. Ported from jquery-caret.
<textarea id="test-input" class="ring-input">
Lorem ipsum
dolor sit amet
</textarea>
<div>
<a href="" id="cursor-action" class="ring-link">Set caret position</a>
</div>
import '@jetbrains/ring-ui/components/input/input.scss';
import '@jetbrains/ring-ui/components/link/link__legacy.css';
import Caret from '@jetbrains/ring-ui/components/caret/caret';
const targetEl = document.getElementById('test-input');
const caret = new Caret(targetEl);
document.getElementById('cursor-action').addEventListener('click', event => {
caret.focus();
caret.setPosition(4);
event.preventDefault();
})