undate
Undoable update for HTMLTextAreaElement
Install
npm install --save undate
Usage
import {update, wrapCursor} from 'undate';
const textareaElement = document.getElementById('textarea');
.value; //=> ''
textareaElement
// Update whole value
update(textareaElement, 'string before cursor', 'optional string after cursor');
.value; //=> 'string before cursoroptional string after cursor'
textareaElement
// Update around the cursor
wrapCursor(textareaElement, ' _', '_ ');
.value; //=> 'string before cursor __ optional string after cursor'
textareaElement
// Press cmd-z
.value; //=> 'string before cursoroptional string after cursor'
textareaElement
.setSelectionRange(14, 27);
textareaElement
.value; //=> 'string before cursoroptional string after cursor'
textareaElement// ^^^^^^^^^^^^^^ selected
wrapCursor(textareaElement, '**', '**');
.value; //=> 'string before **cursoroptional** string after cursor'
textareaElement// ^^^^^^^^^^^^^^ selected
// Press cmd-z
.value; //=> 'string before cursoroptional string after cursor'
textareaElement// ^^^^^^^^^^^^^^ selected
// Press cmd-z
.value; //=> '' textareaElement
License
The MIT License