Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("combines appended transactions in the event started by the base transaction", () => {
let state = mkState(doc(p("x")), {plugins: [new Plugin({
appendTransaction: (_trs, _old, state) => {
if (state.doc.content.size == 4) return state.tr.insert(1, schema.text("A"))
}
})]})
state = state.apply(state.tr.insert(2, schema.text("I")))
ist(state.doc, doc(p("AxI")), eq)
ist(undoDepth(state), 1)
state = command(state, undo)
ist(state.doc, doc(p("x")), eq)
})
it("joins adjacent text", () =>
from([schema.text("a"), schema.text("b")], p("ab")))
})
it("allows typing over a leaf node", () => {
let state = new TestState({doc: doc(p("a"), "<a>", hr, p("b")), schema})
state.nodeSel(3)
state.apply(state.tr.replaceSelectionWith(schema.text("x")))
ist(state.doc, doc(p("a"), p("x"), p("b")), eq)
ist(state.selection.head, 5)
ist(state.selection.anchor, 5)
})
</a>
it("respects the side option on widgets", () => {
let d = doc(p("foo"))
let set = build(d, {pos: 3, side: -1, name: "a"}, {pos: 3, name: "b"})
let tr = new Transform(d).replaceWith(3, 3, schema.text("ay"))
let result = set.map(tr.mapping, tr.doc).find().map(d => d.from + "-" + d.spec.name).sort().join(", ")
ist(result, "3-a, 5-b")
})
it("properly maps selection when rebasing", () => {
let state = mkState(doc(p("123456789ABCD")))
state = state.apply(state.tr.setSelection(TextSelection.create(state.doc, 6, 13)))
state = state.apply(state.tr.delete(6, 13))
let rebase = state.tr.insert(6, schema.text("6789ABC")).insert(14, schema.text("E")).delete(6, 13)
.setMeta("rebased", 1).setMeta("addToHistory", false)
rebase.mapping.setMirror(0, 2)
state = state.apply(rebase)
state = command(state, undo)
})
})
appendTransaction: (_trs, _old, state) => {
if (state.doc.content.size == 4) return state.tr.insert(1, schema.text("A"))
}
})]})
tr => tr.replaceWith(2, 2, schema.text(".")).replaceWith(4, 4, schema.text("?")))
ist(str(set), "[0: [2-3]]")
let {doc0, set0, set, tr} = mk(doc(p("abcd")), tr => tr
.replaceWith(2, 2, schema.text("c"))
.delete(3, 5))
let set1 = ChangeSet.create(doc0).addSteps(tr.docs[1], [tr.mapping.maps[0]], ["a"])