Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("should ignore the event", () => {
const value = initialValue;
const fakeTransform = fake();
const plugins = [AutoReplacePlugin(fakeTransform)];
let simulator = new Editor({ value, plugins });
// Press enter
simulator.run("onKeyDown", keyEvent("Enter"));
expect(fakeTransform.callCount).to.equal(0);
});
});
it("should return the last word", () => {
const editor = new Editor({ value: Plain.deserialize("hello world") });
// Anchor at the end of the first word
expect(getLastWord(editor.moveForward(5))).to.equal("hello");
// Anchor at the beginning of the second word
expect(getLastWord(editor.moveForward(1))).to.equal("");
// Anchor at the end of the second word
expect(getLastWord(editor.moveForward(5))).to.equal("world");
});
});
fixtures(__dirname, 'commands', ({ module }) => {
const { input, output, options = {}, plugins: module_plugins } = module
const fn = module.default
const editor = new Editor({
plugins: module_plugins ? plugins.concat(module_plugins) : plugins,
})
const opts = { preserveSelection: true, ...options }
// if (Object.keys(options).length) {
// throw new TypeError('bad test, cannot use options yet');
// }
const inputSyncDoc = toSyncDocument(input.document.toJSON());
editor.setValue(input)
fn(editor)
// re-apply the operations from the test
const actualSyncDoc = editor.operations.reduce((doc, op) => applyOperation(doc, op), inputSyncDoc);
const actualDoc = toSlateDocument(actualSyncDoc)
const createUnnormalizedValue = children => {
const editor = new Editor({
normalize: false
});
const value = html`
${children}
`;
editor.setValue(value);
return editor.value;
};
const editor = new Editor(options);
return { editor, createValue, createUnnormalizedValue };
};
const createUnnormalizedValue = children => {
const editor = new Editor({
normalize: false
});
const value = html`
${children}
`;
editor.setValue(value);
return editor.value;
};
this.tmp.resolves++
const react = TheReactPlugin({
...this.props,
editor: this,
value: this.props.value || this.state.value,
})
const onChange = change => {
if (this.tmp.mounted) {
this.handleChange(change)
} else {
this.tmp.change = change
}
}
this.controller = new Controller(
{ plugins: [react], onChange },
{ controller: this, construct: false }
)
this.controller.run('onConstruct')
}
)
export default function(opts: Opts) {
return new SlateEditor(opts)
}
{Array.from(Array(10)).map(() => (
This is editable <b>rich</b> text, <i>much</i> better than a
textarea!
))}
)
const editor = new Editor({ value })
editor.moveToRangeOfDocument()
value = editor.value
module.exports.input = function() {
return value
}
{Array.from(Array(10)).map(() => (
This is editable <b>rich</b> text, <i>much</i> better than a
textarea!
))}
)
const editor = new Editor({ value })
editor.moveToRangeOfDocument()
value = editor.value
module.exports.input = () => {
return value
}
{Array.from(Array(10)).map(() => (
This is editable <b>rich</b> text, <i>much</i> better than a
textarea!
))}
)
const editor = new Editor({ value })
editor.moveToRangeOfDocument()
value = editor.value
module.exports.input = function() {
return value
}