Skip to content

Commit

Permalink
DomainEditor we are green again
Browse files Browse the repository at this point in the history
SQUASHED: DomainEditor-we-are-green-again,
  • Loading branch information
JensLincke committed Nov 8, 2023
1 parent de929f9 commit 257c5db
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/client/domain-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export class DomainObject {
}
}


static edit(rootDomainObject, sourceNew, notUsedEdit, debugInfo={} ) {


Expand Down Expand Up @@ -248,6 +249,8 @@ export class DomainObject {
}
}

rootDomainObject.log("edit: " + Array.from(scriptGenerator.actions)
.map(ea => ea.type + " " + ea.node.type + " " + ea.node.id).join("\n "))

for(let action of scriptGenerator.actions) {
action.node.id = parseInt(action.node.id)
Expand Down Expand Up @@ -428,11 +431,10 @@ export class TreeSitterDomainObject extends DomainObject {
// newEndPosition: loc(newTo).asTreeSitter(),
// }

DomainObject.edit(this.rootNode(), livelyCodeMirror.value)

livelyCodeMirror.dispatchEvent(new CustomEvent("domain-code-changed", {detail: {node: this, edit: edit}}))

this.updateReplacements()
// This is the task of the editor to figure it out based on the text change
// DomainObject.edit(this.rootNode(), livelyCodeMirror.value)
// livelyCodeMirror.dispatchEvent(new CustomEvent("domain-code-changed", {detail: {node: this, edit: edit}}))
// this.updateReplacements()
}

get isTreeSitter() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/tools/domain-code-explorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#log {
white-space: pre;
overflow: auto;
max-height: 100px
max-height: 300px
}

</style>
Expand Down
7 changes: 3 additions & 4 deletions src/components/tools/domain-code-explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,15 @@ export default class DomainCodeExplorer extends Morph {
var newSource = this.editor.getText()
this.sourceEditor.setText(newSource)



DomainObject.edit(this.domainObjectInspector.targetObject, newSource, undefined, {
DomainObject.edit(this.domainObject, newSource, undefined, {
newAST: (ast) => {

this.astInspector.inspect(ast.rootNode);
}
})

this.domainObjectInspector.inspect(this.domainObjectInspector.targetObject)
this.domainObject.updateReplacements()
this.domainObjectInspector.inspect(this.domainObject)

// TODO
// this.treeSitterRootNode = evt.detail.node.debugNewAST.rootNode
Expand Down
23 changes: 21 additions & 2 deletions test/domain-code-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ a = 3`


letObj.setText(livelyCodeMirror, "const")

// maybe this should go into setText... but then we get problems with cycles/doing things twice...
DomainObject.edit(obj, livelyCodeMirror.value)
obj.updateReplacements()

expect(livelyCodeMirror.value, "codemirror is updated").to.match(/const a/)


Expand Down Expand Up @@ -488,6 +493,10 @@ const b = a`
expect(letReplacement.type).to.equal("let")

letReplacement.target.setText(livelyCodeMirror, "const")

// maybe this should go into setText... but then we get problems with cycles/doing things twice...
DomainObject.edit(domainObject, livelyCodeMirror.value)
domainObject.updateReplacements()

expect(livelyCodeMirror.value).to.equal(`// hello
const a = 3 + 4
Expand Down Expand Up @@ -557,14 +566,24 @@ const b = a`


letReplacement.onClick()
debugger

// TODO this should be called by the editor
DomainObject.edit(domainObject, livelyCodeMirror.value)
domainObject.updateReplacements()



var constReplacement = domainObject.children[2].children[0]
constReplacement.livelyCodeMirror = livelyCodeMirror
expect(constReplacement.isReplacement, "const isReplacement").to.be.true


constReplacement.onClick()
// TODO this should be called by the editor
DomainObject.edit(domainObject, livelyCodeMirror.value)
domainObject.updateReplacements()



expect(livelyCodeMirror.value).to.match(/let b/)
expect(domainObject.treeSitter.childCount, "childCount after replacement").to.equal(3)
expect(domainObject.children.length, "children after replacement").to.equal(3)
Expand Down

0 comments on commit 257c5db

Please sign in to comment.