Skip to content

Commit 157b12b

Browse files
committed
fix: Fix value binding issue in the editor.
1 parent 16907f9 commit 157b12b

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

Example/Example/ContentView.swift

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,9 @@ import SwiftUI
99
import CodeMirror
1010

1111
let jsonString = """
12-
{
13-
"private": true,
14-
"scripts": {
15-
"start": "rollup -c"
16-
},
17-
"dependencies": {
18-
"@codemirror/lang-css": "^6.0.0",
19-
"@codemirror/lang-html": "^6.0.0",
20-
"@codemirror/lang-javascript": "^6.0.0",
21-
"@codemirror/lang-json": "^6.0.0",
22-
"@codemirror/lang-xml": "^6.0.0",
23-
24-
"@codemirror/language-data": "^6.0.0",
25-
"@codemirror/theme-one-dark": "^6.0.0",
26-
27-
"@rollup/plugin-node-resolve": "^15.0.2",
28-
"@rollup/plugin-terser": "^0.4.0",
29-
"codemirror": "^6.0.0",
30-
"rollup": "^4.0.0",
31-
"rollup-plugin-sizes": "~1.1.0"
32-
}
33-
}
12+
<body>
13+
<h1>DevHub</h1>
14+
</body>
3415
"""
3516

3617
struct ContentView: View {
@@ -39,7 +20,7 @@ struct ContentView: View {
3920
@State var lineNumber = true
4021
@State var foldGutter = false
4122
@State var readOnly = false
42-
@State var language: Language = .json
23+
@State var language: Language = .html
4324
@State var theme: Themes = .vscodedark
4425
@State var enabledSearch = false
4526
@State var count: Int = 0

Sources/CodeMirror/web.bundle/codemirror.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codemirrorjs/codemirror.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ function setLanguage(lang) {
247247
}
248248

249249
function setContent(text) {
250+
let currentValue = editorView.state.doc.toString();
251+
if (text === currentValue) {
252+
return;
253+
}
250254
editorView.dispatch({
251255
changes: { from: 0, to: editorView.state.doc.length, insert: text },
252256
});

0 commit comments

Comments
 (0)