undate
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

undate

Undoable update for HTMLTextAreaElement

NPM version Build Status Code Climate

Install

npm install --save undate

Usage

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

License

The MIT License

Readme

Keywords

Package Sidebar

Install

npm i undate

Weekly Downloads

9,719

Version

0.3.0

License

MIT

Unpacked Size

11 kB

Total Files

11

Last publish

Collaborators

  • yuku-t