stream-monaco 0.0.14 → 0.0.15

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/README.md CHANGED
@@ -80,6 +80,13 @@ The `useMonaco()` function returns an object with the following methods:
80
80
  - **`setUpdateThrottleMs(ms)`** - Change update throttle at runtime
81
81
  - **`getUpdateThrottleMs()`** - Get current throttle value
82
82
 
83
+ #### Diff streaming highlight tip
84
+
85
+ Monaco's diff computation is async and cancels/restarts when models change. If you stream updates too frequently (e.g. per token / every frame), the diff may only finish once streaming stops, so the difference highlights appear "at the end".
86
+
87
+ - Set `diffUpdateThrottleMs` (default: 50) to let the diff worker complete intermediate computations during streaming.
88
+ - Set it to `0` to restore pure RAF batching (most responsive, but may delay diff highlights under heavy streaming).
89
+
83
90
  ### Install
84
91
 
85
92
  ```bash
package/dist/index.cjs CHANGED
@@ -516,11 +516,15 @@ var DiffEditorManager = class {
516
516
  revealBatchOnIdleMsOption;
517
517
  scrollWatcherSuppressionMs = 500;
518
518
  diffScrollWatcherSuppressionTimer = null;
519
- appendBufferDiff = [];
519
+ appendBufferOriginalDiff = [];
520
+ appendBufferModifiedDiff = [];
520
521
  appendBufferDiffScheduled = false;
522
+ diffUpdateThrottleMs = 50;
523
+ lastAppendFlushTimeDiff = 0;
524
+ appendFlushThrottleTimerDiff = null;
521
525
  rafScheduler = createRafScheduler();
522
526
  diffHeightManager = null;
523
- constructor(options, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, revealDebounceMsOption) {
527
+ constructor(options, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, revealDebounceMsOption, diffUpdateThrottleMsOption) {
524
528
  this.options = options;
525
529
  this.maxHeightValue = maxHeightValue;
526
530
  this.maxHeightCSS = maxHeightCSS;
@@ -531,6 +535,40 @@ var DiffEditorManager = class {
531
535
  this.diffAutoScroll = diffAutoScroll;
532
536
  this.revealDebounceMsOption = revealDebounceMsOption;
533
537
  }
538
+ scheduleFlushAppendBufferDiff() {
539
+ if (this.appendBufferDiffScheduled) return;
540
+ this.appendBufferDiffScheduled = true;
541
+ const schedule = () => {
542
+ this.rafScheduler.schedule("appendDiff", () => this.flushAppendBufferDiff());
543
+ };
544
+ const throttle = this.diffUpdateThrottleMs;
545
+ if (!throttle) {
546
+ schedule();
547
+ return;
548
+ }
549
+ const now = Date.now();
550
+ const since = now - this.lastAppendFlushTimeDiff;
551
+ if (since >= throttle) {
552
+ schedule();
553
+ return;
554
+ }
555
+ if (this.appendFlushThrottleTimerDiff != null) return;
556
+ const wait = throttle - since;
557
+ this.appendFlushThrottleTimerDiff = setTimeout(() => {
558
+ this.appendFlushThrottleTimerDiff = null;
559
+ schedule();
560
+ }, wait);
561
+ }
562
+ flushOriginalAppendBufferSync() {
563
+ if (!this.originalModel) return;
564
+ if (this.appendBufferOriginalDiff.length === 0) return;
565
+ this.rafScheduler.cancel("appendDiff");
566
+ this.appendBufferDiffScheduled = false;
567
+ const text = this.appendBufferOriginalDiff.join("");
568
+ this.appendBufferOriginalDiff.length = 0;
569
+ if (!text) return;
570
+ this.appendToModel(this.originalModel, text);
571
+ }
534
572
  computedHeight() {
535
573
  var _originalEditor$getMo, _modifiedEditor$getMo, _originalEditor$getSc, _modifiedEditor$getSc;
536
574
  if (!this.diffEditorView) return Math.min(1 * 18 + padding, this.maxHeightValue);
@@ -778,6 +816,7 @@ var DiffEditorManager = class {
778
816
  });
779
817
  this.lastKnownOriginalCode = originalCode;
780
818
  this.lastKnownModifiedCode = modifiedCode;
819
+ this.diffUpdateThrottleMs = this.options.diffUpdateThrottleMs ?? 50;
781
820
  this.shouldAutoScrollDiff = !!(this.autoScrollInitial && this.diffAutoScroll);
782
821
  if (this.diffScrollWatcher) {
783
822
  this.diffScrollWatcher.dispose();
@@ -894,7 +933,7 @@ var DiffEditorManager = class {
894
933
  const prevM = this.lastKnownModifiedCode;
895
934
  let didImmediate = false;
896
935
  if (originalCode !== prevO && originalCode.startsWith(prevO)) {
897
- this.appendToModel(this.originalModel, originalCode.slice(prevO.length));
936
+ this.appendOriginal(originalCode.slice(prevO.length));
898
937
  this.lastKnownOriginalCode = originalCode;
899
938
  didImmediate = true;
900
939
  }
@@ -919,8 +958,11 @@ var DiffEditorManager = class {
919
958
  }
920
959
  const prev = this.lastKnownOriginalCode ?? this.originalModel.getValue();
921
960
  if (prev === newCode) return;
922
- if (newCode.startsWith(prev) && prev.length < newCode.length) this.appendToModel(this.originalModel, newCode.slice(prev.length));
923
- else this.applyMinimalEditToModel(this.originalModel, prev, newCode);
961
+ if (newCode.startsWith(prev) && prev.length < newCode.length) this.appendOriginal(newCode.slice(prev.length), codeLanguage);
962
+ else {
963
+ this.flushOriginalAppendBufferSync();
964
+ this.applyMinimalEditToModel(this.originalModel, prev, newCode);
965
+ }
924
966
  this.lastKnownOriginalCode = newCode;
925
967
  }
926
968
  updateModified(newCode, codeLanguage) {
@@ -970,8 +1012,8 @@ var DiffEditorManager = class {
970
1012
  const lang = processedLanguage(codeLanguage);
971
1013
  if (lang && this.originalModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.originalModel, lang);
972
1014
  }
973
- this.appendToModel(this.originalModel, appendText);
974
- this.lastKnownOriginalCode = this.originalModel.getValue();
1015
+ this.appendBufferOriginalDiff.push(appendText);
1016
+ this.scheduleFlushAppendBufferDiff();
975
1017
  }
976
1018
  appendModified(appendText, codeLanguage) {
977
1019
  if (!this.diffEditorView || !this.modifiedModel || !appendText) return;
@@ -979,11 +1021,8 @@ var DiffEditorManager = class {
979
1021
  const lang = processedLanguage(codeLanguage);
980
1022
  if (lang && this.modifiedModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, lang);
981
1023
  }
982
- this.appendBufferDiff.push(appendText);
983
- if (!this.appendBufferDiffScheduled) {
984
- this.appendBufferDiffScheduled = true;
985
- this.rafScheduler.schedule("appendDiff", () => this.flushAppendBufferDiff());
986
- }
1024
+ this.appendBufferModifiedDiff.push(appendText);
1025
+ this.scheduleFlushAppendBufferDiff();
987
1026
  }
988
1027
  setLanguage(language, languages$1) {
989
1028
  if (!languages$1.includes(language)) {
@@ -1007,7 +1046,12 @@ var DiffEditorManager = class {
1007
1046
  this.pendingDiffUpdate = null;
1008
1047
  this.rafScheduler.cancel("appendDiff");
1009
1048
  this.appendBufferDiffScheduled = false;
1010
- this.appendBufferDiff.length = 0;
1049
+ this.appendBufferOriginalDiff.length = 0;
1050
+ this.appendBufferModifiedDiff.length = 0;
1051
+ if (this.appendFlushThrottleTimerDiff != null) {
1052
+ clearTimeout(this.appendFlushThrottleTimerDiff);
1053
+ this.appendFlushThrottleTimerDiff = null;
1054
+ }
1011
1055
  this.rafScheduler.cancel("content-size-change-diff");
1012
1056
  this.rafScheduler.cancel("sync-last-known-modified");
1013
1057
  if (this.diffScrollWatcher) {
@@ -1056,7 +1100,12 @@ var DiffEditorManager = class {
1056
1100
  this.pendingDiffUpdate = null;
1057
1101
  this.rafScheduler.cancel("appendDiff");
1058
1102
  this.appendBufferDiffScheduled = false;
1059
- this.appendBufferDiff.length = 0;
1103
+ this.appendBufferOriginalDiff.length = 0;
1104
+ this.appendBufferModifiedDiff.length = 0;
1105
+ if (this.appendFlushThrottleTimerDiff != null) {
1106
+ clearTimeout(this.appendFlushThrottleTimerDiff);
1107
+ this.appendFlushThrottleTimerDiff = null;
1108
+ }
1060
1109
  if (this.diffScrollWatcher) {
1061
1110
  this.diffScrollWatcher.dispose();
1062
1111
  this.diffScrollWatcher = null;
@@ -1108,6 +1157,7 @@ var DiffEditorManager = class {
1108
1157
  }
1109
1158
  const { original, modified, lang } = this.pendingDiffUpdate;
1110
1159
  this.pendingDiffUpdate = null;
1160
+ this.flushOriginalAppendBufferSync();
1111
1161
  this.flushModifiedAppendBufferSync();
1112
1162
  if (lang) {
1113
1163
  const plang = processedLanguage(lang);
@@ -1148,25 +1198,31 @@ var DiffEditorManager = class {
1148
1198
  }
1149
1199
  flushModifiedAppendBufferSync() {
1150
1200
  if (!this.modifiedModel) return;
1151
- if (this.appendBufferDiff.length === 0) return;
1201
+ if (this.appendBufferModifiedDiff.length === 0) return;
1152
1202
  this.rafScheduler.cancel("appendDiff");
1153
1203
  this.appendBufferDiffScheduled = false;
1154
- const text = this.appendBufferDiff.join("");
1155
- this.appendBufferDiff.length = 0;
1204
+ const text = this.appendBufferModifiedDiff.join("");
1205
+ this.appendBufferModifiedDiff.length = 0;
1156
1206
  if (!text) return;
1157
1207
  this.appendToModel(this.modifiedModel, text);
1158
1208
  }
1159
1209
  async flushAppendBufferDiff() {
1160
1210
  if (!this.diffEditorView) return;
1161
- if (this.appendBufferDiff.length === 0) return;
1211
+ if (this.appendBufferOriginalDiff.length === 0 && this.appendBufferModifiedDiff.length === 0) return;
1212
+ this.lastAppendFlushTimeDiff = Date.now();
1162
1213
  this.appendBufferDiffScheduled = false;
1214
+ if (this.originalModel && this.appendBufferOriginalDiff.length > 0) {
1215
+ const oText = this.appendBufferOriginalDiff.join("");
1216
+ this.appendBufferOriginalDiff.length = 0;
1217
+ if (oText) this.appendToModel(this.originalModel, oText);
1218
+ }
1163
1219
  const me = this.diffEditorView.getModifiedEditor();
1164
1220
  const model = me.getModel();
1165
1221
  if (!model) {
1166
- this.appendBufferDiff.length = 0;
1222
+ this.appendBufferModifiedDiff.length = 0;
1167
1223
  return;
1168
1224
  }
1169
- let parts = this.appendBufferDiff.splice(0);
1225
+ let parts = this.appendBufferModifiedDiff.splice(0);
1170
1226
  const prevLineInit = model.getLineCount();
1171
1227
  const totalText = parts.join("");
1172
1228
  const totalChars = totalText.length;
@@ -1241,7 +1297,7 @@ var DiffEditorManager = class {
1241
1297
  return;
1242
1298
  }
1243
1299
  const text = totalText;
1244
- this.appendBufferDiff.length = 0;
1300
+ this.appendBufferModifiedDiff.length = 0;
1245
1301
  prevLine = model.getLineCount();
1246
1302
  const lastColumn = model.getLineMaxColumn(prevLine);
1247
1303
  const range = new monaco_shim_exports.Range(prevLine, lastColumn, prevLine, lastColumn);
@@ -2451,7 +2507,7 @@ function useMonaco(monacoOptions = {}) {
2451
2507
  try {
2452
2508
  monaco_shim_exports.editor.setTheme(initialThemeName);
2453
2509
  } catch {}
2454
- diffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs);
2510
+ diffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs, monacoOptions.diffUpdateThrottleMs);
2455
2511
  diffEditorView = await diffMgr.createDiffEditor(container, originalCode, modifiedCode, language, initialThemeName);
2456
2512
  if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
2457
2513
  const models = diffMgr.getDiffModels();
package/dist/index.d.cts CHANGED
@@ -69,6 +69,18 @@ interface MonacoOptions extends monaco$1.editor.IStandaloneEditorConstructionOpt
69
69
  * - Default (library): 50
70
70
  */
71
71
  updateThrottleMs?: number;
72
+ /**
73
+ * Time window (ms) used to throttle diff streaming updates in addition to RAF batching.
74
+ * This affects `appendOriginal`/`appendModified` and the fast-path append branches of `updateDiff`.
75
+ *
76
+ * Why: Monaco's diff computation is async and cancels/restarts when models change.
77
+ * If you apply edits every frame (or per token), the diff may only finish once
78
+ * streaming stops, so the highlights appear "at the end".
79
+ *
80
+ * - 0 means only RAF-based coalescing (more responsive, but can starve diff computation).
81
+ * - Default (library): 50
82
+ */
83
+ diffUpdateThrottleMs?: number;
72
84
  /**
73
85
  * When attempting the "minimal edit" algorithm, if prev.length + next.length
74
86
  * exceeds this number the library will fall back to full `setValue` to avoid
package/dist/index.d.ts CHANGED
@@ -68,6 +68,18 @@ interface MonacoOptions extends monaco$1.editor.IStandaloneEditorConstructionOpt
68
68
  * - Default (library): 50
69
69
  */
70
70
  updateThrottleMs?: number;
71
+ /**
72
+ * Time window (ms) used to throttle diff streaming updates in addition to RAF batching.
73
+ * This affects `appendOriginal`/`appendModified` and the fast-path append branches of `updateDiff`.
74
+ *
75
+ * Why: Monaco's diff computation is async and cancels/restarts when models change.
76
+ * If you apply edits every frame (or per token), the diff may only finish once
77
+ * streaming stops, so the highlights appear "at the end".
78
+ *
79
+ * - 0 means only RAF-based coalescing (more responsive, but can starve diff computation).
80
+ * - Default (library): 50
81
+ */
82
+ diffUpdateThrottleMs?: number;
71
83
  /**
72
84
  * When attempting the "minimal edit" algorithm, if prev.length + next.length
73
85
  * exceeds this number the library will fall back to full `setValue` to avoid
package/dist/index.js CHANGED
@@ -488,11 +488,15 @@ var DiffEditorManager = class {
488
488
  revealBatchOnIdleMsOption;
489
489
  scrollWatcherSuppressionMs = 500;
490
490
  diffScrollWatcherSuppressionTimer = null;
491
- appendBufferDiff = [];
491
+ appendBufferOriginalDiff = [];
492
+ appendBufferModifiedDiff = [];
492
493
  appendBufferDiffScheduled = false;
494
+ diffUpdateThrottleMs = 50;
495
+ lastAppendFlushTimeDiff = 0;
496
+ appendFlushThrottleTimerDiff = null;
493
497
  rafScheduler = createRafScheduler();
494
498
  diffHeightManager = null;
495
- constructor(options, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, revealDebounceMsOption) {
499
+ constructor(options, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, revealDebounceMsOption, diffUpdateThrottleMsOption) {
496
500
  this.options = options;
497
501
  this.maxHeightValue = maxHeightValue;
498
502
  this.maxHeightCSS = maxHeightCSS;
@@ -503,6 +507,40 @@ var DiffEditorManager = class {
503
507
  this.diffAutoScroll = diffAutoScroll;
504
508
  this.revealDebounceMsOption = revealDebounceMsOption;
505
509
  }
510
+ scheduleFlushAppendBufferDiff() {
511
+ if (this.appendBufferDiffScheduled) return;
512
+ this.appendBufferDiffScheduled = true;
513
+ const schedule = () => {
514
+ this.rafScheduler.schedule("appendDiff", () => this.flushAppendBufferDiff());
515
+ };
516
+ const throttle = this.diffUpdateThrottleMs;
517
+ if (!throttle) {
518
+ schedule();
519
+ return;
520
+ }
521
+ const now = Date.now();
522
+ const since = now - this.lastAppendFlushTimeDiff;
523
+ if (since >= throttle) {
524
+ schedule();
525
+ return;
526
+ }
527
+ if (this.appendFlushThrottleTimerDiff != null) return;
528
+ const wait = throttle - since;
529
+ this.appendFlushThrottleTimerDiff = setTimeout(() => {
530
+ this.appendFlushThrottleTimerDiff = null;
531
+ schedule();
532
+ }, wait);
533
+ }
534
+ flushOriginalAppendBufferSync() {
535
+ if (!this.originalModel) return;
536
+ if (this.appendBufferOriginalDiff.length === 0) return;
537
+ this.rafScheduler.cancel("appendDiff");
538
+ this.appendBufferDiffScheduled = false;
539
+ const text = this.appendBufferOriginalDiff.join("");
540
+ this.appendBufferOriginalDiff.length = 0;
541
+ if (!text) return;
542
+ this.appendToModel(this.originalModel, text);
543
+ }
506
544
  computedHeight() {
507
545
  var _originalEditor$getMo, _modifiedEditor$getMo, _originalEditor$getSc, _modifiedEditor$getSc;
508
546
  if (!this.diffEditorView) return Math.min(1 * 18 + padding, this.maxHeightValue);
@@ -750,6 +788,7 @@ var DiffEditorManager = class {
750
788
  });
751
789
  this.lastKnownOriginalCode = originalCode;
752
790
  this.lastKnownModifiedCode = modifiedCode;
791
+ this.diffUpdateThrottleMs = this.options.diffUpdateThrottleMs ?? 50;
753
792
  this.shouldAutoScrollDiff = !!(this.autoScrollInitial && this.diffAutoScroll);
754
793
  if (this.diffScrollWatcher) {
755
794
  this.diffScrollWatcher.dispose();
@@ -866,7 +905,7 @@ var DiffEditorManager = class {
866
905
  const prevM = this.lastKnownModifiedCode;
867
906
  let didImmediate = false;
868
907
  if (originalCode !== prevO && originalCode.startsWith(prevO)) {
869
- this.appendToModel(this.originalModel, originalCode.slice(prevO.length));
908
+ this.appendOriginal(originalCode.slice(prevO.length));
870
909
  this.lastKnownOriginalCode = originalCode;
871
910
  didImmediate = true;
872
911
  }
@@ -891,8 +930,11 @@ var DiffEditorManager = class {
891
930
  }
892
931
  const prev = this.lastKnownOriginalCode ?? this.originalModel.getValue();
893
932
  if (prev === newCode) return;
894
- if (newCode.startsWith(prev) && prev.length < newCode.length) this.appendToModel(this.originalModel, newCode.slice(prev.length));
895
- else this.applyMinimalEditToModel(this.originalModel, prev, newCode);
933
+ if (newCode.startsWith(prev) && prev.length < newCode.length) this.appendOriginal(newCode.slice(prev.length), codeLanguage);
934
+ else {
935
+ this.flushOriginalAppendBufferSync();
936
+ this.applyMinimalEditToModel(this.originalModel, prev, newCode);
937
+ }
896
938
  this.lastKnownOriginalCode = newCode;
897
939
  }
898
940
  updateModified(newCode, codeLanguage) {
@@ -942,8 +984,8 @@ var DiffEditorManager = class {
942
984
  const lang = processedLanguage(codeLanguage);
943
985
  if (lang && this.originalModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.originalModel, lang);
944
986
  }
945
- this.appendToModel(this.originalModel, appendText);
946
- this.lastKnownOriginalCode = this.originalModel.getValue();
987
+ this.appendBufferOriginalDiff.push(appendText);
988
+ this.scheduleFlushAppendBufferDiff();
947
989
  }
948
990
  appendModified(appendText, codeLanguage) {
949
991
  if (!this.diffEditorView || !this.modifiedModel || !appendText) return;
@@ -951,11 +993,8 @@ var DiffEditorManager = class {
951
993
  const lang = processedLanguage(codeLanguage);
952
994
  if (lang && this.modifiedModel.getLanguageId() !== lang) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, lang);
953
995
  }
954
- this.appendBufferDiff.push(appendText);
955
- if (!this.appendBufferDiffScheduled) {
956
- this.appendBufferDiffScheduled = true;
957
- this.rafScheduler.schedule("appendDiff", () => this.flushAppendBufferDiff());
958
- }
996
+ this.appendBufferModifiedDiff.push(appendText);
997
+ this.scheduleFlushAppendBufferDiff();
959
998
  }
960
999
  setLanguage(language, languages$1) {
961
1000
  if (!languages$1.includes(language)) {
@@ -979,7 +1018,12 @@ var DiffEditorManager = class {
979
1018
  this.pendingDiffUpdate = null;
980
1019
  this.rafScheduler.cancel("appendDiff");
981
1020
  this.appendBufferDiffScheduled = false;
982
- this.appendBufferDiff.length = 0;
1021
+ this.appendBufferOriginalDiff.length = 0;
1022
+ this.appendBufferModifiedDiff.length = 0;
1023
+ if (this.appendFlushThrottleTimerDiff != null) {
1024
+ clearTimeout(this.appendFlushThrottleTimerDiff);
1025
+ this.appendFlushThrottleTimerDiff = null;
1026
+ }
983
1027
  this.rafScheduler.cancel("content-size-change-diff");
984
1028
  this.rafScheduler.cancel("sync-last-known-modified");
985
1029
  if (this.diffScrollWatcher) {
@@ -1028,7 +1072,12 @@ var DiffEditorManager = class {
1028
1072
  this.pendingDiffUpdate = null;
1029
1073
  this.rafScheduler.cancel("appendDiff");
1030
1074
  this.appendBufferDiffScheduled = false;
1031
- this.appendBufferDiff.length = 0;
1075
+ this.appendBufferOriginalDiff.length = 0;
1076
+ this.appendBufferModifiedDiff.length = 0;
1077
+ if (this.appendFlushThrottleTimerDiff != null) {
1078
+ clearTimeout(this.appendFlushThrottleTimerDiff);
1079
+ this.appendFlushThrottleTimerDiff = null;
1080
+ }
1032
1081
  if (this.diffScrollWatcher) {
1033
1082
  this.diffScrollWatcher.dispose();
1034
1083
  this.diffScrollWatcher = null;
@@ -1080,6 +1129,7 @@ var DiffEditorManager = class {
1080
1129
  }
1081
1130
  const { original, modified, lang } = this.pendingDiffUpdate;
1082
1131
  this.pendingDiffUpdate = null;
1132
+ this.flushOriginalAppendBufferSync();
1083
1133
  this.flushModifiedAppendBufferSync();
1084
1134
  if (lang) {
1085
1135
  const plang = processedLanguage(lang);
@@ -1120,25 +1170,31 @@ var DiffEditorManager = class {
1120
1170
  }
1121
1171
  flushModifiedAppendBufferSync() {
1122
1172
  if (!this.modifiedModel) return;
1123
- if (this.appendBufferDiff.length === 0) return;
1173
+ if (this.appendBufferModifiedDiff.length === 0) return;
1124
1174
  this.rafScheduler.cancel("appendDiff");
1125
1175
  this.appendBufferDiffScheduled = false;
1126
- const text = this.appendBufferDiff.join("");
1127
- this.appendBufferDiff.length = 0;
1176
+ const text = this.appendBufferModifiedDiff.join("");
1177
+ this.appendBufferModifiedDiff.length = 0;
1128
1178
  if (!text) return;
1129
1179
  this.appendToModel(this.modifiedModel, text);
1130
1180
  }
1131
1181
  async flushAppendBufferDiff() {
1132
1182
  if (!this.diffEditorView) return;
1133
- if (this.appendBufferDiff.length === 0) return;
1183
+ if (this.appendBufferOriginalDiff.length === 0 && this.appendBufferModifiedDiff.length === 0) return;
1184
+ this.lastAppendFlushTimeDiff = Date.now();
1134
1185
  this.appendBufferDiffScheduled = false;
1186
+ if (this.originalModel && this.appendBufferOriginalDiff.length > 0) {
1187
+ const oText = this.appendBufferOriginalDiff.join("");
1188
+ this.appendBufferOriginalDiff.length = 0;
1189
+ if (oText) this.appendToModel(this.originalModel, oText);
1190
+ }
1135
1191
  const me = this.diffEditorView.getModifiedEditor();
1136
1192
  const model = me.getModel();
1137
1193
  if (!model) {
1138
- this.appendBufferDiff.length = 0;
1194
+ this.appendBufferModifiedDiff.length = 0;
1139
1195
  return;
1140
1196
  }
1141
- let parts = this.appendBufferDiff.splice(0);
1197
+ let parts = this.appendBufferModifiedDiff.splice(0);
1142
1198
  const prevLineInit = model.getLineCount();
1143
1199
  const totalText = parts.join("");
1144
1200
  const totalChars = totalText.length;
@@ -1213,7 +1269,7 @@ var DiffEditorManager = class {
1213
1269
  return;
1214
1270
  }
1215
1271
  const text = totalText;
1216
- this.appendBufferDiff.length = 0;
1272
+ this.appendBufferModifiedDiff.length = 0;
1217
1273
  prevLine = model.getLineCount();
1218
1274
  const lastColumn = model.getLineMaxColumn(prevLine);
1219
1275
  const range = new monaco_shim_exports.Range(prevLine, lastColumn, prevLine, lastColumn);
@@ -2423,7 +2479,7 @@ function useMonaco(monacoOptions = {}) {
2423
2479
  try {
2424
2480
  monaco_shim_exports.editor.setTheme(initialThemeName);
2425
2481
  } catch {}
2426
- diffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs);
2482
+ diffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs, monacoOptions.diffUpdateThrottleMs);
2427
2483
  diffEditorView = await diffMgr.createDiffEditor(container, originalCode, modifiedCode, language, initialThemeName);
2428
2484
  if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
2429
2485
  const models = diffMgr.getDiffModels();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stream-monaco",
3
3
  "type": "module",
4
- "version": "0.0.14",
4
+ "version": "0.0.15",
5
5
  "description": "A framework-agnostic library for integrating Monaco Editor with Shiki highlighting, optimized for streaming updates.",
6
6
  "author": "Simon He",
7
7
  "license": "MIT",