Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

undate

yuku-t43.7kMIT0.3.0TypeScript support: included

Undoable update for HTMLTextAreaElement

textarea

readme

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

changelog

Change Log

All notable changes to this project will be documented in this file.

This project adheres to Semantic Versioning.

This change log adheres to keepachangelog.com.

Unreleased

0.3.0 - 2018-04-18

Changed

  • Rewrite in TypeScript

0.2.4 - 2018-01-24

Fixed

  • Dispatch input event in IE correctly

0.2.3 - 2017-10-29

Fixed

  • Fix potential infinite loop

0.2.2 - 2017-08-31

Fixed

  • Dispatch input event in firefox and IE

0.2.1 - 2017-07-05

Fixed

  • Fix element focus bug in safari
  • Fix bug that removing part of heading string causes wrong result

0.2.0 - 2017-07-03

Changed

  • Export update function as "update" not as default

Fixed

  • Enable to import update and wrapCursor functions individually

0.1.2 - 2017-06-28

Fixed

  • Handle inactive textarea element
  • Enable to insert a string similar to texts around the cursor

0.1.1 - 2017-06-28

Fixed

  • ES2015 compatible

0.1.0 - 2017-06-28

Added

  • Initial release