Comparing version 4.3.6 to 4.3.7
@@ -40,3 +40,5 @@ import { diffChars } from 'diff'; | ||
const addedCallback = (change) => { | ||
const node = textNodes[currentNodeIdx] ?? createTemporaryNode(container); | ||
const node = textNodes.at(currentNodeIdx) ?? createTemporaryNode(container); | ||
if (!node) | ||
return; // Could not create a temporary node | ||
const text = node.textContent ?? ''; | ||
@@ -49,29 +51,18 @@ const pre = text.slice(0, currentNodeCharIdx); | ||
const removedCallback = (change) => { | ||
// Use the Selection object to delete removed text | ||
const startNodeIdx = currentNodeIdx; | ||
const startNodeCharIdx = currentNodeCharIdx; | ||
advance(change.value.length); | ||
const endNodeIdx = currentNodeIdx; | ||
let endNodeCharIdx = currentNodeCharIdx; | ||
const startNode = textNodes[startNodeIdx]; | ||
let endNode = textNodes[endNodeIdx]; | ||
if (!endNode) { | ||
// Remove everything | ||
endNode = textNodes.at(-1); | ||
endNodeCharIdx = endNode.textContent?.length ?? 0; | ||
let charsToRemove = change.value.length; | ||
while (charsToRemove > 0) { | ||
const node = textNodes.at(currentNodeIdx); | ||
if (!node) | ||
return; // Could not find a node | ||
const text = node.textContent ?? ''; | ||
const availableNodeChars = text.length - currentNodeCharIdx; | ||
const stepsTaken = Math.min(availableNodeChars, charsToRemove); | ||
node.textContent = | ||
text.slice(0, currentNodeCharIdx) + text.slice(currentNodeCharIdx + stepsTaken); | ||
charsToRemove -= stepsTaken; | ||
if (stepsTaken == availableNodeChars) { | ||
currentNodeIdx++; | ||
currentNodeCharIdx = 0; | ||
} | ||
} | ||
const range = new Range(); | ||
range.setStart(startNode, startNodeCharIdx); | ||
range.setEnd(endNode, endNodeCharIdx); | ||
const selection = window.getSelection(); | ||
if (!selection) | ||
return; | ||
const initialRanges = new Array(selection.rangeCount).map((_, i) => selection.getRangeAt(i)); | ||
selection.removeAllRanges(); | ||
selection.addRange(range); | ||
selection.deleteFromDocument(); | ||
initialRanges.forEach(selection.addRange); | ||
// Go back to start | ||
currentNodeIdx = startNodeIdx; | ||
currentNodeCharIdx = startNodeCharIdx; | ||
}; | ||
@@ -78,0 +69,0 @@ for (const change of diff) { |
@@ -19,3 +19,3 @@ { | ||
}, | ||
"version": "4.3.6", | ||
"version": "4.3.7", | ||
"scripts": { | ||
@@ -22,0 +22,0 @@ "dev": "vite dev", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
289426
7632