Skip to content

Commit

Permalink
use untyped model API to support editor rules generated by MPS (3)
Browse files Browse the repository at this point in the history
  • Loading branch information
slisson committed Nov 24, 2023
1 parent e5eb7da commit 993cfe4
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.modelix.kernelf.KernelfLanguages
import org.modelix.metamodel.ModelData
import org.modelix.metamodel.descendants
import org.modelix.metamodel.ofType
import org.modelix.metamodel.untyped
import org.modelix.model.ModelFacade
import org.modelix.model.api.IBranch
import org.modelix.model.api.PBranch
Expand All @@ -36,7 +37,7 @@ open class IncrementalLayoutAfterInsertJS {
val engine = EditorEngine(IncrementalEngine())
KernelfEditor.register(engine)
testSuite = branch.computeRead { branch.getArea().getRoot().allChildren.ofType<N_Module>().models.rootNodes.ofType<N_TestSuite>().first() }
editor = JsEditorComponent(engine, { editorState -> branch.computeRead { engine.createCell(editorState, testSuite) } })
editor = JsEditorComponent(engine, { editorState -> branch.computeRead { engine.createCell(editorState, testSuite.untyped()) } })
assertTestItem = branch.computeRead { testSuite.descendants<N_AssertTestItem>().drop(1).first() }
editor.selectAfterUpdate {
val cell = editor.resolveNodeCell(assertTestItem)!!.firstLeaf().nextLeafs(true).first { it.isVisible() }
Expand All @@ -55,16 +56,17 @@ open class IncrementalLayoutAfterInsertJS {
@Test
fun domAfterInsert() {
val containerElement = document.create.div()
var consumer = JSDom(containerElement.ownerDocument!!).let { vdom -> IncrementalVirtualDOMBuilder(vdom, vdom.wrap(containerElement)) }
val generatedHtmlMap = GeneratedHtmlMap()
var consumer = JSDom(containerElement.ownerDocument!!).let { vdom -> IncrementalVirtualDOMBuilder(vdom, vdom.wrap(containerElement), generatedHtmlMap) }
val initialHtml = editor.getRootCell().layout.toHtml(consumer).unwrap().outerHTML

editor.processKeyEvent(JSKeyboardEvent(JSKeyboardEventType.KEYDOWN, KnownKeys.Enter))
consumer = JSDom(containerElement.ownerDocument!!).let { vdom -> IncrementalVirtualDOMBuilder(vdom, vdom.wrap(containerElement)) }
consumer = JSDom(containerElement.ownerDocument!!).let { vdom -> IncrementalVirtualDOMBuilder(vdom, vdom.wrap(containerElement), generatedHtmlMap) }
val incrementalHtml = editor.getRootCell().layout.toHtml(consumer).unwrap().outerHTML

editor.clearLayoutCache()

consumer = JSDom(containerElement.ownerDocument!!).let { vdom -> IncrementalVirtualDOMBuilder(vdom, vdom.wrap(containerElement)) }
consumer = JSDom(containerElement.ownerDocument!!).let { vdom -> IncrementalVirtualDOMBuilder(vdom, vdom.wrap(containerElement), generatedHtmlMap) }
val nonIncrementalHtml = editor.getRootCell().layout.toHtml(consumer).unwrap().outerHTML
assertEquals(nonIncrementalHtml, incrementalHtml)
}
Expand Down

0 comments on commit 993cfe4

Please sign in to comment.