@vscode/web-editors 0.0.2-151 → 0.0.2-153

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6315,13 +6315,22 @@ var TextDocumentSync = class {
6315
6315
  * The operation that applies `edits` (offsets into `oldText`, in any order) to
6316
6316
  * `oldText`, if they don't overlap and turn it into `newText`; `undefined`
6317
6317
  * otherwise, for example if a change was missed.
6318
+ *
6319
+ * Each edit is trimmed to the part that actually changes: VS Code reports
6320
+ * reloading a file or changing its line endings as one replacement of the
6321
+ * whole text, which would otherwise move every position to its end.
6318
6322
  */
6319
6323
  function fromDocumentEdits(oldText, edits, newText) {
6320
6324
  const builder = new TextOperationBuilder();
6321
6325
  let offset = 0;
6322
6326
  for (const edit of [...edits].sort((a, b) => a.offset - b.offset)) {
6323
6327
  if (edit.offset < offset || edit.length < 0 || edit.offset + edit.length > oldText.length) return;
6324
- builder.retain(edit.offset - offset).insert(edit.newText).delete(edit.length);
6328
+ builder.retain(edit.offset - offset);
6329
+ const trimmed = diffText(oldText.slice(edit.offset, edit.offset + edit.length), edit.newText);
6330
+ for (const component of trimmed.components) if (component.kind === "retain") builder.retain(component.length);
6331
+ else if (component.kind === "insert") builder.insert(component.text);
6332
+ else builder.delete(component.length);
6333
+ builder.retain(edit.length - trimmed.baseSpan);
6325
6334
  offset = edit.offset + edit.length;
6326
6335
  }
6327
6336
  const operation = builder.build();