| @@ -61,6 +61,28 @@ describe("a dialect's commands", () => { |
| 61 | 61 | expect(run(lists, "- milk", [enter, undo]).state.doc).toBe("- milk"); |
| 62 | 62 | }); |
| 63 | 63 | |
| 64 | + test("see the text an input carries, so a paste can become something else", () => { |
| 65 | + const links: Dialect = { |
| 66 | + commands: { |
| 67 | + insertFromPaste: (state, text) => { |
| 68 | + if (!text.startsWith("https://")) return null; |
| 69 | + const { from, to } = selected(state.selection); |
| 70 | + return { change: { from, to, insert: `@${text}` }, selection: caret(from + text.length + 1), group: "other" }; |
| 71 | + }, |
| 72 | + }, |
| 73 | + }; |
| 74 | + const paste = (text: string) => (model: Model): Action => ({ kind: "edit", inputType: "insertFromPaste", text, selection: at(model), at: 0 }); |
| 75 | + expect(run(links, "", [paste("https://example.com")]).state.doc).toBe("@https://example.com"); |
| 76 | + expect(run(links, "", [paste("milk")]).state.doc).toBe("milk"); |
| 77 | + }); |
| 78 | + |
| 79 | + test("get an empty text from keys and chords", () => { |
| 80 | + const seen: string[] = []; |
| 81 | + const watching: Dialect = { commands: { bold: (_state, text) => (seen.push(text), null) } }; |
| 82 | + run(watching, "milk", [(model) => ({ kind: "key", name: "bold", selection: at(model), at: 0 })]); |
| 83 | + expect(seen).toEqual([""]); |
| 84 | + }); |
| 85 | + |
| 64 | 86 | test("make the element cancel their inputTypes", () => { |
| 65 | 87 | const own: Dialect = { commands: { insertOrderedList: () => null } }; |
| 66 | 88 | expect(handlesInputType("insertOrderedList")).toBe(false); |