selection-update

Computing input selection updates on external content changes, as if we used browser managed undo and redo.
API
calculateUpdate(currentSelection, currentValue, newValue);
Usage
import { calculateUpdate } from 'selection-update';
function updateInput($input, newValue) {
var newSelection;
if (document.activeElement === $input) {
newSelection = selectionUpdate(getSelection($input), $input.value, newValue);
}
$input.value = value;
if (newSelection) {
setSelection($input, selection);
}
}
Related
License
MIT
1.0.0
CHORE
: turn into module
CHORE
: export contents via named exports
...
Check git log
for earlier versions.