diff --git a/src/client/domain-code.js b/src/client/domain-code.js
index 0e42514d0..a9bab6592 100644
--- a/src/client/domain-code.js
+++ b/src/client/domain-code.js
@@ -219,15 +219,15 @@ export class DomainObject {
})
// modify only after traversion
- // for(let domainObject of domainObjectByOldId.values()) {
- // var newNode = newTreeSitterNodeByOldId.get(domainObject.id)
- // if (newNode) {
- // domainObject.treeSitter = newNode
- // domainObjectById.set(domainObject.id, domainObject)
- // } else {
- // obsolteDomainObjects.push(domainObject)
- // }
- // }
+ for(let domainObject of domainObjectByOldId.values()) {
+ var newNode = newTreeSitterNodeByOldId.get(domainObject.id)
+ if (newNode) {
+ domainObject.treeSitter = newNode
+ domainObjectById.set(domainObject.id, domainObject)
+ } else {
+ obsolteDomainObjects.push(domainObject)
+ }
+ }
for(let action of scriptGenerator.actions) {
@@ -242,7 +242,9 @@ export class DomainObject {
if (!parentDomainObject) {
throw new Error(`parent domain object (${action.parent.type} ${action.parent.id}) not found`)
}
- var newDomainObject = new TreeSitterDomainObject(action.node)
+
+ let treeSitter = newTreeSitterNodeById.get(action.node.id)
+ var newDomainObject = new TreeSitterDomainObject(treeSitter)
newDomainObject.children = []
newDomainObject.parent = parentDomainObject
diff --git a/src/components/tools/domain-code-explorer.html b/src/components/tools/domain-code-explorer.html
index d3dd81309..70c82d730 100644
--- a/src/components/tools/domain-code-explorer.html
+++ b/src/components/tools/domain-code-explorer.html
@@ -57,6 +57,12 @@
background: steelblue;
}
+ #log {
+ white-space: pre;
+ overflow: auto;
+ max-height: 100px
+ }
+
@@ -92,5 +98,6 @@
+
\ No newline at end of file
diff --git a/src/components/tools/domain-code-explorer.js b/src/components/tools/domain-code-explorer.js
index 76fb12c62..338e7384a 100644
--- a/src/components/tools/domain-code-explorer.js
+++ b/src/components/tools/domain-code-explorer.js
@@ -66,6 +66,12 @@ export default class DomainCodeExplorer extends Morph {
if (evt.button === 2) this.autoUpdate = !this.autoUpdate;
this.update();
}
+
+ log(s) {
+ let log = this.get("#log")
+ log.append({s}
)
+ log.scrollTop = log.scrollHeight;
+ }
/*MD ## Initialization MD*/
@@ -163,10 +169,10 @@ export default class DomainCodeExplorer extends Morph {
}
onDomainCodeChanged() {
+ this.log("domain code changed " + this.isUpdating + " length: " + this.editor.getText().length)
if (this.lastSource == this.editor.getText()) return
- lively.notify("domain code changed " + this.isUpdating)
// this.domainObjectInspector.inspect(this.domainObjectInspector.targetObject)
// prevent cycle....
@@ -206,7 +212,7 @@ export default class DomainCodeExplorer extends Morph {
async update() {
this.lastSource = this.source
- lively.notify("on source code changed")
+ this.log("source code changed, length: " + this.source.length + "")
try {
var node = await this.astInspector.treeSitterParse(this.source)
diff --git a/test/domain-code-test.js b/test/domain-code-test.js
index bf1886e82..554027a0b 100644
--- a/test/domain-code-test.js
+++ b/test/domain-code-test.js
@@ -176,6 +176,59 @@ a = 3`
})
+
+
+ it('reconciles change when inserting ', () => {
+ let sourceOriginal = `let a = 3`
+ let sourceNew = `let a = 3\nx`
+ let root = TreeSitterDomainObject.fromSource(sourceOriginal)
+
+
+ DomainObject.edit(root, sourceNew)
+
+
+ let exressionStatement = root.children[1]
+ expect(exressionStatement.type).equals("expression_statement")
+ expect(exressionStatement.treeSitter.startIndex).equals(10)
+
+
+ })
+
+ it('reconciles update the source code', () => {
+ let sourceOriginal = `let a = 3`
+ let sourceNew = `let a = 3\nx`
+ let root = TreeSitterDomainObject.fromSource(sourceOriginal)
+
+ expect(root.treeSitter.tree.rootNode.text, "sourceOriginal").equals(sourceOriginal)
+
+ DomainObject.edit(root, sourceNew)
+
+
+ expect(root.treeSitter.tree.rootNode.text, "sourceNew").equals(sourceNew)
+ })
+
+ it('reconciles change when inserting again', () => {
+ let sourceOriginal = `let a = 3`
+ let sourceNew = `let a = 3\nx`
+ let root = TreeSitterDomainObject.fromSource(sourceOriginal)
+
+ DomainObject.edit(root, sourceNew)
+
+
+
+ let secondEdit = `let a = 3\nx\n`
+
+ expect(root.children.length).equals(2)
+
+ debugger
+ DomainObject.edit(root, secondEdit, undefined, {actions: editScript => {
+
+ expect(editScript.actions.length, "actions").equals(0)
+ }})
+
+ expect(root.children.length).equals(2)
+ })
+
it('reconciles changes with nothing ', () => {