add tests for diffAtCaret
This commit is contained in:
parent
595dc82543
commit
419c800167
2 changed files with 82 additions and 1 deletions
|
@ -52,6 +52,13 @@ export function diffDeletion(oldStr, newStr) {
|
|||
return {at: firstDiffIdx, removed: oldStr.substr(firstDiffIdx, amount)};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates which string was added and removed around the caret position
|
||||
* @param {String} oldValue the previous value
|
||||
* @param {String} newValue the new value
|
||||
* @param {Number} caretPosition the position of the caret after `newValue` was applied.
|
||||
* @return {object}
|
||||
*/
|
||||
export function diffAtCaret(oldValue, newValue, caretPosition) {
|
||||
const diffLen = newValue.length - oldValue.length;
|
||||
const caretPositionBeforeInput = caretPosition - diffLen;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue