stream-monaco 0.0.1 → 0.0.2

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.cjs CHANGED
@@ -775,7 +775,13 @@ var DiffEditorManager = class {
775
775
  else this.applyMinimalEditToModel(o, prevO, original);
776
776
  this.lastKnownOriginalCode = original;
777
777
  }
778
- const prevM = this.lastKnownModifiedCode;
778
+ let prevM = this.lastKnownModifiedCode;
779
+ if (this.appendBufferDiff.length > 0) try {
780
+ prevM = m.getValue();
781
+ this.lastKnownModifiedCode = prevM;
782
+ } catch {
783
+ prevM = this.lastKnownModifiedCode ?? "";
784
+ }
779
785
  const prevMLineCount = m.getLineCount();
780
786
  if (prevM !== modified) {
781
787
  if (modified.startsWith(prevM) && prevM.length < modified.length) this.appendToModel(m, modified.slice(prevM.length));
@@ -1098,7 +1104,7 @@ var EditorManager = class {
1098
1104
  if (newLineCount$1 !== prevLineCount$1) this.maybeScrollToBottom(newLineCount$1);
1099
1105
  return;
1100
1106
  }
1101
- const prevCode = this.lastKnownCode ?? this.editorView.getValue();
1107
+ const prevCode = this.appendBuffer.length > 0 ? this.editorView.getValue() : this.lastKnownCode ?? this.editorView.getValue();
1102
1108
  if (prevCode === newCode) return;
1103
1109
  if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
1104
1110
  const suffix = newCode.slice(prevCode.length);
@@ -1865,13 +1871,22 @@ function useMonaco(monacoOptions = {}) {
1865
1871
  const { code: newCode, lang: codeLanguage } = pendingUpdate;
1866
1872
  pendingUpdate = null;
1867
1873
  const processedCodeLanguage = processedLanguage(codeLanguage);
1868
- let prevCode = lastKnownCode;
1869
- if (prevCode == null) try {
1874
+ let prevCode = null;
1875
+ if (appendBuffer.length > 0) try {
1870
1876
  prevCode = model.getValue();
1871
1877
  lastKnownCode = prevCode;
1872
1878
  } catch {
1873
1879
  prevCode = "";
1874
1880
  }
1881
+ else {
1882
+ prevCode = lastKnownCode;
1883
+ if (prevCode == null) try {
1884
+ prevCode = model.getValue();
1885
+ lastKnownCode = prevCode;
1886
+ } catch {
1887
+ prevCode = "";
1888
+ }
1889
+ }
1875
1890
  if (prevCode === newCode) return;
1876
1891
  const languageId = model.getLanguageId();
1877
1892
  if (languageId !== processedCodeLanguage) {
package/dist/index.js CHANGED
@@ -747,7 +747,13 @@ var DiffEditorManager = class {
747
747
  else this.applyMinimalEditToModel(o, prevO, original);
748
748
  this.lastKnownOriginalCode = original;
749
749
  }
750
- const prevM = this.lastKnownModifiedCode;
750
+ let prevM = this.lastKnownModifiedCode;
751
+ if (this.appendBufferDiff.length > 0) try {
752
+ prevM = m.getValue();
753
+ this.lastKnownModifiedCode = prevM;
754
+ } catch {
755
+ prevM = this.lastKnownModifiedCode ?? "";
756
+ }
751
757
  const prevMLineCount = m.getLineCount();
752
758
  if (prevM !== modified) {
753
759
  if (modified.startsWith(prevM) && prevM.length < modified.length) this.appendToModel(m, modified.slice(prevM.length));
@@ -1070,7 +1076,7 @@ var EditorManager = class {
1070
1076
  if (newLineCount$1 !== prevLineCount$1) this.maybeScrollToBottom(newLineCount$1);
1071
1077
  return;
1072
1078
  }
1073
- const prevCode = this.lastKnownCode ?? this.editorView.getValue();
1079
+ const prevCode = this.appendBuffer.length > 0 ? this.editorView.getValue() : this.lastKnownCode ?? this.editorView.getValue();
1074
1080
  if (prevCode === newCode) return;
1075
1081
  if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
1076
1082
  const suffix = newCode.slice(prevCode.length);
@@ -1837,13 +1843,22 @@ function useMonaco(monacoOptions = {}) {
1837
1843
  const { code: newCode, lang: codeLanguage } = pendingUpdate;
1838
1844
  pendingUpdate = null;
1839
1845
  const processedCodeLanguage = processedLanguage(codeLanguage);
1840
- let prevCode = lastKnownCode;
1841
- if (prevCode == null) try {
1846
+ let prevCode = null;
1847
+ if (appendBuffer.length > 0) try {
1842
1848
  prevCode = model.getValue();
1843
1849
  lastKnownCode = prevCode;
1844
1850
  } catch {
1845
1851
  prevCode = "";
1846
1852
  }
1853
+ else {
1854
+ prevCode = lastKnownCode;
1855
+ if (prevCode == null) try {
1856
+ prevCode = model.getValue();
1857
+ lastKnownCode = prevCode;
1858
+ } catch {
1859
+ prevCode = "";
1860
+ }
1861
+ }
1847
1862
  if (prevCode === newCode) return;
1848
1863
  const languageId = model.getLanguageId();
1849
1864
  if (languageId !== processedCodeLanguage) {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "stream-monaco",
3
3
  "type": "module",
4
- "version": "0.0.1",
5
- "packageManager": "pnpm@10.17.1",
4
+ "version": "0.0.2",
5
+ "packageManager": "pnpm@10.18.3",
6
6
  "description": "A framework-agnostic library for integrating Monaco Editor with Shiki highlighting, optimized for streaming updates.",
7
7
  "author": "Simon He",
8
8
  "license": "MIT",
@@ -73,14 +73,14 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "@shikijs/monaco": "^3.13.0",
76
- "alien-signals": "^2.0.0",
76
+ "alien-signals": "^2.0.8",
77
77
  "shiki": "^3.13.0"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@antfu/eslint-config": "^5.4.1",
81
- "@types/node": "^18.19.127",
81
+ "@types/node": "^18.19.130",
82
82
  "bumpp": "^8.2.1",
83
- "eslint": "^9.36.0",
83
+ "eslint": "^9.38.0",
84
84
  "lint-staged": "^13.3.0",
85
85
  "picocolors": "^1.1.1",
86
86
  "playwright": "1.38.0",
@@ -88,7 +88,7 @@
88
88
  "rimraf": "^3.0.2",
89
89
  "tsdown": "^0.12.9",
90
90
  "tsx": "^3.14.0",
91
- "typescript": "^5.9.2",
91
+ "typescript": "^5.9.3",
92
92
  "vitest": "^3.2.4"
93
93
  },
94
94
  "lint-staged": {